How can I make a group of checkboxes mutually exclusive?

前端 未结 6 1918
名媛妹妹
名媛妹妹 2020-12-16 11:54

I have to make mutually exculsive checkboxes. I have come across numerous examples that do it giving example of one checkbox group. One example is at http://blog.schuager.c

6条回答
  •  天涯浪人
    2020-12-16 12:20

    Like I said in my comment, you should really use elements for this. Give them the same name and they work almost the same way:

    
    
    

    The only significant difference is that, once one of them is selected, at least one of them has to be on (ie, you can't uncheck them again).

    If you really feel the need to do it with check boxes, remind yourself that users with JavaScript disabled will be able to select all the options if they like. If you still feel the need to do it, then you'll need to give each checkbox group a unique class name. Then, handle the change event of each checkbox element and uncheck all the other elements matching the same class name as the clicked element.

提交回复
热议问题