Catch checked change event of a checkbox

后端 未结 9 1924
盖世英雄少女心
盖世英雄少女心 2020-12-12 17:09

How do I to catch check/uncheck event of with jQuery?

相关标签:
9条回答
  • 2020-12-12 17:35

    The click will affect a label if we have one attached to the input checkbox?

    I think that is better to use the .change() function

    <input type="checkbox" id="something" />
    
    $("#something").change( function(){
      alert("state changed");
    });
    
    0 讨论(0)
  • 2020-12-12 17:37

    Use the :checked selector to determine the checkbox's state:

    $('input[type=checkbox]').click(function() {
        if($(this).is(':checked')) {
            ...
        } else {
            ...
        }
    });
    
    0 讨论(0)
  • 2020-12-12 17:39

    use the click event for best compatibility with MSIE

    $(document).ready(function() {
        $("input[type=checkbox]").click(function() {
            alert("state changed");
        });
    });
    
    0 讨论(0)
提交回复
热议问题