当使用 JavaScript/Jquery 禁用或取消选中网格中的所有复选框时,如何禁用按钮? [英] how to disable a button when all the checkboxes in grid are disable or un checked using JavaScript/Jquery?
本文介绍了当使用 JavaScript/Jquery 禁用或取消选中网格中的所有复选框时,如何禁用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网格,其中有 1 个 coulmns 有 checkboxes
.我想当所有复选框都被禁用或未勾选(未勾选)时禁用按钮使用 JavaScript 还是 jQuery?
.Aspx 文件
解决方案 您可以执行以下操作,但您需要使用更具体的选择器对其进行更新,以免影响所有复选框和按钮:
$('input[type=checkbox]').change(function(){var count = $('input[type=checkbox]:checked').length;$('button').prop('disabled', count == 0);});
如果您在加载时也需要它:
$('input[type=checkbox]').change(function(){禁用复选框();});禁用复选框 = 函数(){var count = $('input[type=checkbox]:checked').length;$('button').prop('disabled', count == 0);};禁用复选框();
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) using JavaScript or jQuery?
.Aspx File
<asp:TemplateField HeaderText="Cancel SO Line Item">
<ItemTemplate>
<asp:checkbox ID="cbSOCan" runat="server" ViewStateMode="Enabled" EnableViewState="true"></asp:checkbox>
</ItemTemplate>
<asp:LinkButton CssClass="btn btn-primary" ID="btnCancelItem" runat="server" CausesValidation="False"OnClientClick="return Confirmationbox();"> Cancel Item</asp:LinkButton>
<asp:HiddenField id="hdnval" value=0 runat="server"/>
解决方案
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:
$('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:
$('input[type=checkbox]').change(function(){
disableCheckbox();
});
disableCheckbox = function() {
var count = $('input[type=checkbox]:checked').length;
$('button').prop('disabled', count == 0);
};
disableCheckbox();
这篇关于当使用 JavaScript/Jquery 禁用或取消选中网格中的所有复选框时,如何禁用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文