开发者

jQuery (UI): Detect checking of a checkbox

开发者 https://www.devze.com 2023-01-04 09:26 出处:网络
How can I make jQuery fire an event when a user checks a checkbox? <input type="checkbox" id="test" name="test" /><label for="test">Check me</lab

How can I make jQuery fire an event when a user checks a checkbox?

<input type="checkbox" id="test" name="test" /><label for="test">Check me</label>
开发者_StackOverflow中文版

I could do it with .click though that doesn't work when the user tabs to the checkbox. I wasn't able to find info on this in the API docs or while Googling.


$('#test').bind('change', function(){
    if($(this).is(':checked')){
        // box was checked
    }
});


You're looking for the change event:

$('#test').change(function() { ... });
0

精彩评论

暂无评论...
验证码 换一张
取 消