当使用JavaScript/Jquery禁用或取消选中网格中的所有复选框时,如何禁用按钮?
我有一个网格,其中有1个coulmns有当使用JavaScript/Jquery禁用或取消选中网格中的所有复选框时,如何禁用按钮?,javascript,jquery,asp.net,gridview,Javascript,Jquery,Asp.net,Gridview,我有一个网格,其中有1个coulmns有复选框 禁用所有复选框或取消选中(取消选中)时禁用按钮 使用JavaScript还是jQuery .Aspx文件 <asp:TemplateField HeaderText="Cancel SO Line Item"> <ItemTemplate> <asp:checkbox ID="cbSOCan" runat="server" ViewStateMode="Enabled" EnableVi
复选框
禁用所有复选框或取消选中(取消选中)时禁用按钮
使用JavaScript还是jQuery
.Aspx文件
<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"/>
您可以执行以下操作,但需要使用更具体的选择器对其进行更新,以免影响所有复选框和按钮:
如果您还需要装载:
它只是影响DOM元素,所以它应该能够。需要查看html在DOM中的状态。
$('input[type=checkbox]').change(function(){
var count = $('input[type=checkbox]:checked').length;
$('button').prop('disabled', count == 0);
});
$('input[type=checkbox]').change(function(){
disableCheckbox();
});
disableCheckbox = function() {
var count = $('input[type=checkbox]:checked').length;
$('button').prop('disabled', count == 0);
};
disableCheckbox();