jQuery: make checkboxes act like radio buttons?

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

    If you select "$("input:checkbox")" will select all the checkbox so you can specify the different radio button by using their name.

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

    Below Example will explain

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



    $(this).prop("checked",true); });

提交回复
热议问题