简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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