当网格中的所有复选框都禁用或未使用JavaScript / Jquery检查时如何禁用按钮? [英] how to disable a button when all the checkboxes in grid are disable or un checked using JavaScript/Jquery?

查看:100
本文介绍了当网格中的所有复选框都禁用或未使用JavaScript / Jquery检查时如何禁用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个网格,其中有一个coulmns有复选框。我想
当所有复选框使用JavaScript或jQuery禁用或取消选中(取消选中)

.Aspx文件

 < asp:TemplateField HeaderText =取消所有订单项> 
< ItemTemplate>
< asp:checkbox ID =cbSOCanrunat =serverViewStateMode =EnabledEnableViewState =true>< / asp:checkbox>
< / ItemTemplate>

< asp:LinkBut​​ton CssClass =btn btn-primaryID =btnCancelItemrunat =serverCausesValidation =FalseOnClientClick =return Confirmationbox();>& nbsp ;取消项目< / asp:LinkBut​​ton>
< asp:HiddenField id =hdnvalvalue = 0 runat =server/>


解决方案

你可以做如下的事情,但你需要用更多的特定选择器来更新它,所以它不会影响所有的复选框和按钮:



JS小提琴

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

如果您还需要加载它:



JS小提琴



<$ p $();
> $('input [type = checkbox]')。change(function(){
disableCheckbox();
});

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

disableCheckbox();


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();">&nbsp;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:

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();

这篇关于当网格中的所有复选框都禁用或未使用JavaScript / Jquery检查时如何禁用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆