jQuery - checkboxes like radiobuttons

前端 未结 9 1675
小鲜肉
小鲜肉 2020-12-01 11:07

I have group checkboxes and I like if this group have behaviour like radiobuttons with same name atribute.

Each checkbox has different name.

Only one can be

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 11:34

    I had a similar problem. I couldn't use radio button because the same form had to display multiple choice checkboxes in some situations. I took your markup and wrote this small piece of jQuery:

    $("span.multiGroup input").click(function() {
        $("span.multiGroup input").attr('checked', false);
        $(this).attr('checked', true);
    });
    

提交回复
热议问题