简体   繁体   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

how to make a alert if no check box is selected and button disabled if all the checkbox are disabled in a grid on page load by jQuery 如果没有选中复选框则如何发出警报,如果在jQuery页面加载时网格中禁用了所有复选框,则按钮被禁用

tried 试着

 $( 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"/>

You are missing # for the button to get disabled 您缺少#以禁用该按钮

$( 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