簡體   English   中英

如果沒有選中復選框則發出警報,如果Jquery在頁面加載時在網格中禁用了所有復選框,則禁用按鈕

[英]alert if no check box is selected and button disabled if all checkbox are disabled in a grid on page load by Jquery

如果沒有選中復選框則如何發出警報,如果在jQuery頁面加載時網格中禁用了所有復選框,則按鈕被禁用

試着

 $( document ).ready(function() {
     $('input[type=checkbox]').change(function () {
         disableCheckbox();
    });

    disableCheckbox = function () {
        var count = $('input[type=checkbox]:checked').length;
        $('btnCancelItem').prop('disabled', count == 0);
    };

    disableCheckbox();
});

<asp:LinkButton CssClass="btn btn-primary" ID="btnCancelItem" runat="server" CausesValidation="False"OnClientClick="return Confirmationbox();">&nbsp;Cancel Item</asp:LinkButton>
<asp:HiddenField id="hdnval" value=0 runat="server"/>

您缺少#以禁用該按鈕

$( document ).ready(function() {
  $('input[type=checkbox]').change(function () {
    disableCheckbox();
  });

  disableCheckbox = function () {
   var count = $('input[type=checkbox]:checked').length;
   if (count == 0) { alert("nothing selected") } 
   $('#btnCancelItem').prop('disabled', count == 0);
  };

  disableCheckbox();
});
  disableCheckbox = function () {
                    //checked check-boxes length
                    checkedCount = $('#CP_Main_gvPOItems input[type=checkbox]:checked').length;

                    //check-boxes length
                    checkboxCount = $('#CP_Main_gvPOItems input[type=checkbox]').length;

                    //if no check-box is selected then alert
                    //                if (checkedCount == 0) {
                    //                    alert('No check-box is selected');
                    // }
                    //check for all disabled check-boxes
                    //var disableCheckBox = 0;
                    $('#CP_Main_gvPOItems input[type=checkbox]').each(function () {
                        if ($(this).is(':disabled')) {
                            disableCheckBox++;
                        }
                    });

                    //if all check-boxes are disabled then disable button
                    if (checkboxCount == disableCheckBox) {

                        $('#CP_Main_btnCancelItem').attr("disabled", "disabled"); //# is missing
                    }
                };




                disableCheckbox();

                $("#CP_Main_btnCancelItem").button().click(function () {

                    var checkedCount = $('#CP_Main_gvPOItems input[type=checkbox]:checked').length;

                    var isDisabled = $(checkedCount).is(':disabled');
                    // alert(isDisabled);
                    var status = false;
                    if (checkedCount == 0 && isDisabled) {
                        alert('No check-box is selected');
                        status = false;
                    }
                    else if (!isDisabled && checkedCount > 0) {
                        alert('Are you sure you want to cancel selected Record(s)?');
                        status = true;
                    }
                    return status;
                });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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