81,092
社区成员
发帖
与我相关
我的任务
分享
选择字数类型
<input type="radio" name="type" value="1"/>0~1000字
<input type="radio" name="type" value="2"/>1000~3000字
<input type="radio" name="type" value="3"/>3000~4000字
<input type="radio" name="type" value="4"/>4000~5000字
填写您字数<input type="text" name="currency"/>
<input type="submit" name="submit" value="submit"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<script>
function fun(){
var a=document.form1.currency.value;
if(document.form1.type[0].checked)//判断是否选中 type[0]表示第1个
{
if(a.length <1000 &&a.length>0)//判断范围
{
alert("yes");
}
else {
alert("字数不在这个范围");
}
}
}
</script>
<body>
<form name="form1">选择字数类型 <!--form表单-->
<input type="radio" name="type" value="1"/>0~1000字
<input type="radio" name="type" value="2"/>1000~3000字
<input type="radio" name="type" value="3"/>3000~4000字
<input type="radio" name="type" value="4"/>4000~5000字
填写您字数 <input type="text" name="currency" />
<input type="button" name="submit" value="submit" onclick="fun()"/> <!--type改为button onclick调用javascript-->
</form>
</body>
</html>
function fun(){
var a=document.form1.currency.value;
var aType = document.form1.type;
var bValid = false;
for(var i=0; i<aType.length; i++){
if(aType[i].checked == true){
switch(i){
case 0:
bValid = a>0&&a<1000;
break;
case 1:
bValid = a>1000&&a<3000;
break;
case 2:
bValid = a>3000&&a<4000;
break;
case 3:
bValid = a>4000&&a<5000;
}
}
}
if(bValid){
alert("OK");
} else {
alert("NG");
}
}