两个radio第一个选中禁用某个文本框 第二个选中再启用该文本框  来回选择不能出错 用什么事件最合适 如何写js

解决方案 »

  1.   

    <script>
    function check(){
      if(  ){ 
     
       }
    }
    </script>
    表单form有失去焦点的事件
      

  2.   

    radio的话应该是根据selected的值来判断比较合适。
      

  3.   


    <html>
    <head>
    <title>Sample</title>
    <script type="text/javascript">
    function change(){
    var _text=document.getElementById("text");
    if(radio[0].checked){
    _text.disabled=true;
    }
    if(radio[1].checked){
    _text.disabled=false;
    }
    }
    </script>
    </head>
    <body>
    <input type=radio name="radio" CHECKED onclick="change();" />First
      <input type=radio name="radio" onclick="change();" />Second
      <br/>
      <input type="text" id="text" value="文本框" disabled="true"/>
      
    </body>
    </html>
      

  4.   

    如果是select 和文本框是一样的吗
      

  5.   

    不一样了,隐藏显示都是同样的代码。
    获得select 的值,要用document.getElementById("select").value
      

  6.   

    radio的话应该是根据selected的值来判断比较合适。
      

  7.   

    现在我能让它禁用 但是再点激活时不管用 是怎么回事 下面我贴上代码<input name="toAdd" id="radio1" type="radio" value="重新选择地址" checked onclick="checkSelectAddress()"/>激活 <input name="toAdd" id="radio2" type="radio" value="个人信息地址" onclick="checkSelectAddress()"/>禁用
    function checkSelectAddress(){
    var pro=document.getElementById("pro");
    var city=document.getElementById("city");
    var area=document.getElementById("area");
    var addr=document.getElementById("address")
    var radio=document.getElementsByName("toAdd");
    if(radio[0].checked){
    pro.setAttribute("disabled",true);
    city.setAttribute("disabled",true);
    area.setAttribute("disabled",true);
    addr.setAttribute("disabled",true);
    }
    if(radio[1].checked){
    pro.setAttribute("disabled",false);
    city.setAttribute("disabled",false);
    area.setAttribute("disabled",false);
    addr.setAttribute("disabled",false);
    }
    }