jQuery: make checkboxes act like radio buttons?

后端 未结 11 1648
栀梦
栀梦 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:20

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

    This will do it, although i do agree this might be a bad idea.

    Online example: http://jsfiddle.net/m5EuS/1/

    UPDATE added group separation.

提交回复
热议问题