gpt4 book ai didi

javascript - 通过选中复选框启用多个输入

转载 作者:行者123 更新时间:2023-11-28 19:56:58 26 4
gpt4 key购买 nike

我对 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>

最佳答案

 <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>

关于javascript - 通过选中复选框启用多个输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22373929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com