jQuery: make checkboxes act like radio buttons?

后端 未结 11 1643
栀梦
栀梦 2020-11-28 10:29

Is there a way to make checkboxes act like radio buttons? I assume this could be done with jQuery?



        
11条回答
  •  日久生厌
    2020-11-28 11:18

    basically the same answer as @amosrivera but remove the unchecking of all the checkbox as its necessary. instead use .not()

        $("input:checkbox").click(function(){
            var group = "input:checkbox[name='"+$(this).prop("name")+"']";
            $(group).not(this).prop("checked",false);
        });
    

提交回复
热议问题