Check if checkbox is checked with jQuery

后端 未结 23 3092
忘了有多久
忘了有多久 2020-11-21 23:12

How can I check if a checkbox in a checkbox array is checked using the id of the checkbox array?

I am using the following code, but it always returns the count of ch

23条回答
  •  忘了有多久
    2020-11-21 23:42

    Something like this can help

    togglecheckBoxs =  function( objCheckBox ) {
    
        var boolAllChecked = true;
    
        if( false == objCheckBox.checked ) {
            $('#checkAll').prop( 'checked',false );
        } else {
            $( 'input[id^="someIds_"]' ).each( function( chkboxIndex, chkbox ) {
                if( false == chkbox.checked ) {
                    $('#checkAll').prop( 'checked',false );
                    boolAllChecked = false;
                }
            });
    
            if( true == boolAllChecked ) {
                $('#checkAll').prop( 'checked',true );
            }
        }
    }
    

提交回复
热议问题