如果复选框选中jquery,则禁用选择

我有一个 html 脚本,其中有一个多项选择,当我选中复选框字段时,我想“禁用”。


例子:


<p><input type="checkbox" id="chk_select" name="check" value="ok" "/> deselect</p>


<p>

<select multiple="multiple" name="candidato[]" id="soci" required>

<option value="">-</option>

<option value="Name 1">Name 1</option>

<option value="Name 2">Name 2</option>

</select>

</p>



是否可以使用 jquery 禁用多项选择?



摇曳的蔷薇
浏览 168回答 3
3回答

翻阅古今

试试这个。function checkstate() {&nbsp; &nbsp; document.getElementById('soci').disabled = document.getElementById('chk_select').checked;}<p><input type="checkbox" id="chk_select" name="check" value="ok" onclick="checkstate()"> deselect</p><p><select multiple="multiple" name="candidato[]" id="soci" required><option value="">-</option><option value="Name 1">Name 1</option><option value="Name 2">Name 2</option></select></p>

呼唤远方

希望这有帮助...看法&nbsp;<p>&nbsp; &nbsp; <input type="checkbox" id="chk_select" name="check" value="ok" onclick="myFunction()"/>&nbsp;&nbsp;deselect&nbsp; &nbsp; </p>脚本&nbsp; <script>&nbsp; &nbsp; function myFunction() {&nbsp; &nbsp; &nbsp; var checkBox = document.getElementById("myCheck");&nbsp; &nbsp; &nbsp; if (checkBox.checked == true){&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('soci').disabled = true;&nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; document.getElementById('soci').disabled = false;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; </script>

杨魅力

这会成功的$('input[type="checkbox"]').change(function(){if($(this).is(':checked')){$('select').attr('disabled','disabled')}else{$('select').removeAttr('disabled','disabled')}})<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><p><input type="checkbox" id="chk_select" name="check" value="ok" "/> deselect</p><p><select multiple="multiple" name="candidato[]" id="soci" required ><option value="">-</option><option value="Name 1">Name 1</option><option value="Name 2">Name 2</option></select></p>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript