简体   繁体   English

单击“全选”后,如何取消选中先前选择的其他选定列表项?

[英]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.

相关问题 如何在选择第一个单选输入时选择所有复选框,并在选择第二个单选输入时取消选中所有复选框? (JavaScript)的 - How do I Select All Checkboxes When First Radio Input Selected & Uncheck All Checkboxes when Second radio input selected? (Javascript) 如何回发多选列表中的所有选定项目,使其包含在我的视图模型中? - How do I post back all selected items in a multi-select list so it is included in my view model? 在angularjs中单击按钮(检查选定的电话)后,如何取消选中所有复选框? - How can i uncheck all checkboxes after click button(check selected phones) in angularjs? 如何取消选中多个选定选择器中的选项 - How can I uncheck the options from multiple selected select pickers 在使用JavaScript或JQuery选择HTML中的选定项目之后,如何禁用项目? - How do I disable items after the selected item in an HTML select using JavaScript or JQuery? 尝试选择特定元素。 如何将所有其他未选择的元素更改为 false? - Trying to select a specific element. How do I change all other elements that aren't selected to false? 如果取消选中任何子复选框,如何取消选中“全选”复选框 - How do I uncheck 'select-all' checkbox if any child checkbox gets unchecked 使用Jquery,如何在当前选择的输入元素之后选择所有输入文本元素? - Using Jquery how do I select all input text elements after currently selected input element? 如何隐藏除所选列表以外的所有列表? - How do I hide all lists other than the selected list? 如何从多选 lov 中检索所选项目并将它们与预定列表进行比较,作为 oracle apex 18.2 中的动态操作? - How do I retrieve selected items from a multi-select lov and compare them to a predetermined list as a dynamic action in oracle apex 18.2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM