现在我想做一个判断,下面代码选择字数类型
<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"/>怎样当他填上的数字不是所选的类型时发出警告

解决方案 »

  1.   

    要用js来写,响应input,在onchange方法写回调,当输入焦点离来输入框时就会自动执行。要想在他输入的时候就检查,也可以,自已稍稍研究一下,以前写过一个时间的输入框,能做到即时检验,我已经记不得具体实现了。
      

  2.   

    先把text的字数选出来
    然后和你选中的比较范围,不在范围就报错
      

  3.   

    [code=JS<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <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]其他的一样 
      

  4.   


    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改了一下,呵呵
      

  5.   

    <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> 我没写没选中的情况,你操作的时候先选中第1个按钮,在文本里面输入数据 然后点按钮,不可能没反应的 我才做的 不行给源文件你了