简体   繁体   English

当用户在“复选框”列表中选中一个复选框时,如何禁用该复选框?

[英]How can we disable the checkbox when user check the one of checbox in the Checkboxlist?

I've a table in which first row contains a checkbox list. 我有一个表,其中第一行包含一个复选框列表。 I've a scenario like if user click any checkbox of that list the other should be disabled mode and uncheck the checkbox enable the all checkboxes. 我有一种情况,例如,如果用户单击该列表中的任何复选框,其他应禁用模式,然后取消选中该复选框,则启用所有复选框。

I've tried like to disable the checkbox ,but unable to un-checkbox the checkbox it should to enable all. 我试图禁用该复选框,但无法取消选中该复选框以启用所有功能。

var $checkboxList = $('#tr1 input[type=checkbox]');
            $checkboxList.change(function () {
                $checkboxList.each(function () {
                    if (!this.checked) {
                        this.disabled = true;
                    }
                    else {
                        this.disabled = false;
                    }
                });
            }); 

how can we hold the state of checkboxes in case of paging ? 在分页的情况下,如何保持复选框的状态?

In answer to your first question, you can just set .prop('disabled') based on the value of this.checked : 在回答第一个问题,你可以设置.prop('disabled')基础上的价值this.checked

$checkboxList.change(function () {
    $checkboxList.not(this).prop('disabled', this.checked); 
}); 

Here's a fiddle 这是一个小提琴

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 div仅选中了一个带可能复选框的复选框 - Only one checbox checked with possibility check checkbox by div javascript-如何检查特定数量的checbox并禁用剩余的jQuery - How to check specific number of checbox and disable remaining using jquery? 在Ext Js复选框模型中禁用Checbox - Disable Checbox in Ext Js checkbox model 如果选中了checkboxlist1中的特定列表项,如何禁用checkboxlist2中的某些复选框? - How to disable certain checkbox items in checkboxlist2 if a specific list item from checkboxlist1 is checked? 在检查其他3个复选框时,如何检查和禁用复选框 - How to check and disable a checkbox, when other 3 checkbox are checked, in Angular 使用Javascript选择复选框中的其他项目时,如何禁用它们 - How to disable the other items in a checkboxlist when one of them is selected using Javascript 如果我选中复选框,如何启用复选框中的输入? 因为当我选中输入类型的复选框时,它总是禁用 - How to enable the input in checkbox if i check the checkbox? cuz it always disable when i check the checkbox with input type 如何在单击一个复选框时禁用其他复选框? - How to disable other checkbox on click of one check box? 提交表单时自动检查复选框 - Automatically check checbox when submitting a form 取消选中复选框时如何禁用PHP禁用和清除文本框。 选中/取消选中复选框,具体取决于数据库 - How to disable anPHP disable and clear textbox when checkbox is unchecked. Check/uncheck checkbox depending on database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM