[英]How do I uncheck the other selected list items that was previously select after I click on “Select All”?
I have these codes that allow me to disable all other checkboxes when I check on "Select All" however if I previously did check on other checkboxes before checking on "Select All", previously checked boxes does not get removed but only disabled with the boxes still checked. 我具有这些代码,这些代码可让我在选中“全选”时禁用所有其他复选框,但是,如果我之前在选中“全选”之前确实选中了其他复选框,则先前选中的框不会被删除,而只能与框一起禁用仍然检查。 so how can I uncheck the other selected list items that was previously select after I click on "Select All"?
因此,如何单击“全选”后取消选中其他先前选择的列表项?
<asp:CheckBoxList ID="Checkboxlist1" runat="server" Height="80px" Width="500px" AppendDataBoundItems="True" ViewStateMode="Enabled">
<asp:ListItem Text="Select All" Value="Select All"></asp:ListItem>
</asp:CheckBoxList>
$(function () {
$("#Checkboxlist :checkbox").change(function () {
$("#Checkboxlist :checkbox").click(function () {
var ischecked = $(this).is(":checked");
var val = $(this).val();
//alert(val);
if (val == "Select All") {
if (ischecked) {
$("#Checkboxlist :checkbox").attr('disabled', 'disabled');
$(this).removeAttr('disabled');
$(this).attr('checked', true)
return;
} else {
$("#Checkboxlist :checkbox").removeAttr('disabled');
return;
}
}
});
});
})
In the else
, before return
simply remove the disabled from Select All
: 在
else
,在return
之前,只需从“全Select All
删除禁用者即可:
$(this).removeAttr("disabled");
OR 要么
just edit your selector
for not having the checkbox
whose value is Select All
: 只需编辑
selector
使其没有Select All
checkbox
:
$("#Checkboxlist1:checkbox[value='Select All']")
Code: 码:
if (val == "Select All") {
//if Select All is checked, disable all other checkboxes and uncheck them as well
if (ischecked) {
$("#Checkboxlist1:checkbox").attr("disabled", "disabled"); //disable all checkboxes
$("#Checkboxlist1:checkbox").prop('checked', false); //uncheck all checkboxes
$(this).prop('checked', true); //check the "Select All" checkbox
return;
}
//enable all other checkboxes and uncheck them too
else {
$("#Checkboxlist1:checkbox").removeAttr("disabled"); //enable all checkboxes
$("#Checkboxlist1:checkbox").prop('checked', false); //uncheck all checkboxes
$(this).prop('checked', false); //uncheck the "Select All" checkbox
return;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.