Jquery checkbox inside div checked one at time

前端 未结 2 1981
心在旅途
心在旅途 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 15:52

    I had a similar issue and solved it like so (using part of Arun P Johny's answer - I wanted to share for those of you who might come across this as well.)

    (function($checkbox,options){                               
                $($checkbox).on('change', function() {                  
                    $("input[type='checkbox']").not(this).prop('checked', false);               
                });             
            });
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题