簡體   English   中英

單擊“全選”后,如何取消選中先前選擇的其他選定列表項?

[英]How do 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;
                }
            }
        });
    });
})

else ,在return之前,只需從“全Select All刪除禁用者即可:

$(this).removeAttr("disabled");

要么

只需編輯selector使其沒有Select All checkbox

$("#Checkboxlist1:checkbox[value='Select All']")

碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM