How do I check whether a checkbox is checked in jQuery?

前端 未结 30 3530
花落未央
花落未央 2020-11-21 04:44

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery.

For example, if the age checkbox is

30条回答
  •  既然无缘
    2020-11-21 05:09

    This is some different method to do the same thing:

    $(document).ready(function (){
    
        $('#isAgeSelected').click(function() {
            // $("#txtAge").toggle(this.checked);
    
            // Using a pure CSS selector
            if ($(this.checked)) {
                alert('on check 1');
            };
    
            // Using jQuery's is() method
            if ($(this).is(':checked')) {
                alert('on checked 2');
            };
    
            //  // Using jQuery's filter() method
            if ($(this).filter(':checked')) {
                alert('on checked 3');
            };
        });
    });
    
    
    

提交回复
热议问题