Jquery checkbox inside div checked one at time

前端 未结 2 1982
心在旅途
心在旅途 2021-01-20 15:42

So i have a div thats auto generated and inside are 3 check boxes with different id\'s & names and by default none of them are checked!! If one happens to get checked th

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 16:12

    Use the prop function to change the checked property of checkbox and radio buttons

    $(function(){
        $('input:checkbox').prop('checked', false)
        $('input:checkbox').click(function(){
            if($(this).is(':checked')){
                $('input:checkbox').not(this).prop('checked', false);        
            }
        });
    })
    

    Demo: Fiddle

提交回复
热议问题