Catch checked change event of a checkbox

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

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

9条回答
  •  北海茫月
    2020-12-12 17:20

    
    
    $("#something").click( function(){
       if( $(this).is(':checked') ) alert("checked");
    });
    

    Edit: Doing this will not catch when the checkbox changes for other reasons than a click, like using the keyboard. To avoid this problem, listen to changeinstead of click.

    For checking/unchecking programmatically, take a look at Why isn't my checkbox change event triggered?

提交回复
热议问题