我对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 :(得分: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>