简体   繁体   English

在一组复选框中,一次只能选择一个

[英]in a group of check boxes only allow one to be selected at a time

I want a group of check boxes on a page, when you select a check box I want to clear any other check boxes of checks and just check the one you just clicked on. 我想要页面上的一组复选框,当您选中一个复选框时,我想清除其他所有复选框,然后仅选中您单击的复选框。 I have a fiddle that I thought should work, but it never checks the one you clicked on. 我有一个小提琴琴,我以为应该起作用,但是它永远不会检查您单击的那把琴。 I don't want to use radio buttons as "no selection" is valid as well 我不想使用单选按钮,因为“无选择”也有效

$("#mytable input").change(function(){
$("#mytable input").attr('checked',false);
    $(this).attr('checked',true);
})

jsfiddle jsfiddle

You should rather use radio button with same name. 您应该使用具有相同名称的单选按钮。 using checkboxes, you need to use: 使用复选框,您需要使用:

$("#mytable input").change(function() {
 $("#mytable input").not(this).prop('checked', false);  
});

Working Demo 工作演示

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM