禁用多个文本框当我单击HTML中的复选框时

时间:2014-08-29 05:23:57

标签: html css

<input type='checkbox' name='chk1' value='1' 
    onclick='enable_txtbox("item","item1")'>name<br>
<input type='text' name='name1' id='item' disabled='disabled'><input type='text' 
    name='name1' id='item1' disabled='disabled'><input type='text' name='name1' id='item2'
    disabled='disabled'>

<script>
  function enable_txtbox(id,id1)
    {if(document.getElementById(id).disabled == true)
        {
             document.getElementById(id).disabled = false;
        } else 
             {document.getElementById(id).disabled = true; }
             return true;}
</script>

1 个答案:

答案 0 :(得分:0)

use this:


<script>
    function enable_txtbox(id, id1) {
        var a =(document.getElementsByName("name1"));
        for(var i=0;i<a.length;i++){
            var b=a[i].id;
            if(document.getElementById(b).disabled == true)
            {
                 document.getElementById(b).disabled = false;
            } 
            else 
            {
                document.getElementById(b).disabled = true; 
            }
        }   
            return true;
        }
    </script>