how to disable a button when all the checkboxes in grid are disable or un checked using JavaScript/Jquery?

后端 未结 1 666
既然无缘
既然无缘 2021-01-16 19:00

I have a grid in which I have 1 coulmns has checkboxes.I want to disable a button when all the checkbox are disabled or unticked(uncheked)

1条回答
  •  被撕碎了的回忆
    2021-01-16 19:18

    You can do something like the following, but you'll need to update it with more specific selectors so it doesn't affect all checkboxes and buttons:

    JS Fiddle

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

    And if you need it on load as well:

    JS Fiddle

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

    0 讨论(0)
提交回复
热议问题