现在我想做一个判断,下面代码选择字数类型
<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"/>怎样当他填上的数字不是所选的类型时发出警告
<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"/>怎样当他填上的数字不是所选的类型时发出警告
解决方案 »
- Tomcat运行几天出现的问题!!
- java web的jsp利用access数据库怎么取得access auto_increment的字段?
- 在线等,textarea改行显示(struts)
- URL中文乱码的问题,在线等,急!!!
- 关于JAVA读取excel文件的问题
- tomcat自动调用守护线程存放的路径问题
- 求一 jsp+oracle 计数器,防刷新
- 请问bbs的分页功能是怎么实现的?
- 心情不好,散分!
- cas+shiro,自定义拦截器,第二次获取不到subject中的session信息
- javabean无法MySQL
- To:CSDN 强烈倡议:请将CSDN网站色调调整为黑白来寄托哀思方法很简单请转发
然后和你选中的比较范围,不在范围就报错
<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>
cript][/code]其他的一样
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");
}
}
把上面的js改了一下,呵呵
<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> 我没写没选中的情况,你操作的时候先选中第1个按钮,在文本里面输入数据 然后点按钮,不可能没反应的 我才做的 不行给源文件你了