admin管理员组

文章数量:1244258

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>

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.

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>

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.

Share Improve this question edited Apr 22, 2022 at 7:42 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 21, 2010 at 13:54 MauriceMaurice 4,9407 gold badges42 silver badges51 bronze badges
Add a ment  | 

2 Answers 2

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

You're looking for the change event:

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

本文标签: javascriptjQuery (UI) Detect checking of a checkboxStack Overflow