2014-03-13 267 views
0

我越來越不好帶的形式與javascrpt和投入的問題...... 我有一個由一個複選框和兩個選擇列表由多個團體組成的形式啓用多個輸入,我需要激活當他們的複選框被選中時,組的選擇列表...我怎麼辦?這裏是我的代碼:通過勾選複選框

<input type="checkbox" value="room1" class="bookcheckbox1"><b>Select Room</b> 
Adults<select class="bookselect1"> 
<option value="0">0</option> 
<option value="1">1</option> 
<option value="2">2</option> 
</select> 
Children<select class="bookselect1"> 
<option value="0">0</option> 
<option value="1">1</option> 
</select> 

<input type="checkbox" value="room2" class="bookcheckbox2"><b>Select Room</b> 
Adults<select class="bookselect2"> 
<option value="0">0</option> 
<option value="1">1</option> 
<option value="2">2</option> 
</select> 
Children<select class="bookselect2"> 
<option value="0">0</option> 
<option value="1">1</option> 
</select> 
+0

你被允許使用jQuery? –

回答

3
<body> 
<script type="text/javascript"> 
    function able(obj,x){ 
     if(obj.checked ==true) 
      { 
       document.getElementById("x"+x).disabled=false; 
       document.getElementById("y"+x).disabled=false; 
      } 
     else 
      { 
       document.getElementById("x"+x).disabled=true; 
       document.getElementById("y"+x).disabled=true; 
      } 
    } 
</script> 
<input type="checkbox" value="room1" class="bookcheckbox1" onchange="able(this,1)"><b>Select Room</b> 
Adults<select class="bookselect1" disabled="true" id="x1"> 
<option value="0">0</option> 
<option value="1">1</option> 
<option value="2">2</option> 
</select> 
Children<select class="bookselect1" disabled="true" id="y1"> 
<option value="0">0</option> 
<option value="1">1</option> 
</select> 

<input type="checkbox" value="room2" class="bookcheckbox2" onchange="able(this,2)"><b>Select Room</b> 
Adults<select class="bookselect2" disabled="true" id="x2"> 
<option value="0">0</option> 
<option value="1">1</option> 
<option value="2">2</option> 
</select> 
Children<select class="bookselect2" disabled="true" id="y2"> 
<option value="0">0</option> 
<option value="1">1</option> 
</select> 
</body> 
+0

@ user2132234我希望這會起作用。 –

+0

噢!謝謝!!! – user2132234