Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery禁用,并清除除一个标记为“的”复选框之外的其他复选框;“全部”;_Javascript_Jquery_Checkbox_Html Table - Fatal编程技术网

Javascript JQuery禁用,并清除除一个标记为“的”复选框之外的其他复选框;“全部”;

Javascript JQuery禁用,并清除除一个标记为“的”复选框之外的其他复选框;“全部”;,javascript,jquery,checkbox,html-table,Javascript,Jquery,Checkbox,Html Table,我正在重构现有的复选框选择器。第一个选项是“全部”,下面是单独的选择。如果选择了“全部”,我想禁用其他选项。如果未选中“全部”,则其他选择可用,如果选中任何单个选择,则用户选择“全部”,代码将清除其他选择,并禁用它们 我是jQuery新手,但在选择“全部”时,在“单击”和页面加载时,我都能够以功能为目标 <table id="ctl12" class="dynCheckBoxList"> <tr> <td><input id="ctl12_0"

我正在重构现有的复选框选择器。第一个选项是“全部”,下面是单独的选择。如果选择了“全部”,我想禁用其他选项。如果未选中“全部”,则其他选择可用,如果选中任何单个选择,则用户选择“全部”,代码将清除其他选择,并禁用它们

我是jQuery新手,但在选择“全部”时,在“单击”和页面加载时,我都能够以功能为目标

<table id="ctl12" class="dynCheckBoxList">
<tr>
    <td><input id="ctl12_0" type="checkbox" name="ctl12$0" checked="checked"/><label for="ctl12_0">All</label></td>
</tr>
<tr>
    <td><input id="ctl12_1" type="checkbox" name="ctl12$1"/><label for="ctl12_1">BN</label></td>
</tr>
<tr>
    <td><input id="ctl12_2" type="checkbox" name="ctl12$2"/><label for="ctl12_2">C2</label></td>
</tr>
<tr>
    <td><input id="ctl12_3" type="checkbox" name="ctl12$3"/><label for="ctl12_3">CC</label></td>
</tr>
</table>

我还想重构这个JQuery。我必须写两段独立的代码。If语句将触发,因为页面加载时选中了“All”选择器,但每次用户选择它时(页面加载后)都会触发以下函数。

您可以执行以下操作:

$("#ctl12_0").change(function() {
    var inputs = $("[id^=ctl12]:checkbox").not(this);
    this.checked ? inputs.prop({disabled: true, checked: false}) 
                 : inputs.prop("disabled", false);
}).change();

演示:

很漂亮。谢谢各位。
$("#ctl12_0").change(function() {
    var inputs = $("[id^=ctl12]:checkbox").not(this);
    this.checked ? inputs.prop({disabled: true, checked: false}) 
                 : inputs.prop("disabled", false);
}).change();