<input type="text" name="a" onblur="func(this)">
<input type="text" name="b">function func(a){
   if(a.value=="中国"){
       if(document.getElementsByName("b")[0].value ==""){
           alert("必须输入");
       }
   }else{
       if(document.getElementsByName("b")[0].value ==""){
           alert("必须不能输入数据");
       }
   }
}

解决方案 »

  1.   

    <input type="text" name="a" onblur="func(this)">
    <input type="text" name="b">function func(a){
       if(a.value=="中国"){
           if(document.getElementsByName("b")[0].value ==""){
               alert("必须输入");
           }
       }else{
           if(document.getElementsByName("b")[0].value !=""){
               alert("必须不能输入数据");
           }
       }
    }
      

  2.   

    你的方法只满足等于中国时是可以的,不等于中国时不行。最好有提交按钮。
    <form name="form1" method="post" action="xxx.asp" onSubmit="return CheckSubmit()">
      <input type="text" name="a">
      <input type="text" name="b">
      <input type="submit" name="Submit" value="提交">
    </form>
      

  3.   

    直接禁掉不管输入不输入都没关系了
    <input type="text" name="a" onblur="func(this)">
    <input type="text" name="b">
    <script language=javascript>
    function func(a){
       if(a.value=="中国"){
        document.getElementsByName("b")[0].disabled=false
           if(document.getElementsByName("b")[0].value ==""){
               alert("必须输入");
           }
       }else{
           document.getElementsByName("b")[0].disabled=true
       }
    }
    </script>
      

  4.   

    hbhbhbhbhb1021(天外水火(我要多努力)) 你写的很好,但我实际的和你不一样?不好意思是我没有写清楚我的要求。其实我a文本框里的数据是数据库里调入的不是手工输的,b文本框里才是手工输的。还有什么办法吗?
      

  5.   

    function func(){
     var a=document.getElementsByName("a")[0];
       if(a.value=="中国"){
           if(document.getElementsByName("b")[0].value ==""){
               alert("必须输入");
           }
       }else{
           if(document.getElementsByName("b")[0].value !=""){
               alert("必须不能输入数据");
           }
       }
    }
      

  6.   

    mingxuan3000(铭轩)我现在的a文本框数据是从数据库里调入的不是输的。
      

  7.   

    我是这样:
    <form name="form1" method="post" action="xxx.jsp" >
    <input type="text" name="a" readonly value="<%=y_name%>" onblur="func(this)">
    <input type="text" name="b">
      <input type="submit" name="Submit" value="提交">
    </form>
    <script language=javascript>
    function func(){
     var a=document.getElementsByName("a")[0];
       if(a.value=="中国"){
           if(document.getElementsByName("b")[0].value ==""){
               alert("必须输入");
           }
       }else{
           if(document.getElementsByName("b")[0].value !=""){
               alert("必须不能输入数据");
           }
       }
    }</script>
    试下来不行,后来我直接在a文本框里赋值象下面:
    <form name="form1" method="post" action="xxx.jsp" >
    <input type="text" name="a" readonly value="中国" onblur="func(this)">
    <input type="text" name="b">
      <input type="submit" name="Submit" value="提交">
    </form>
    <script language=javascript>
    function func(){
     var a=document.getElementsByName("a")[0];
       if(a.value=="中国"){
           if(document.getElementsByName("b")[0].value ==""){
               alert("必须输入");
           }
       }else{
           if(document.getElementsByName("b")[0].value !=""){
               alert("必须不能输入数据");
           }
       }
    }</script>
    这样也不行啊!我到底怎么改后才可以呢???