最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery (UI): Detect checking of a checkbox - Stack Overflow

programmeradmin1浏览0评论

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() { ... });
发布评论

评论列表(0)

  1. 暂无评论