【问题标题】:jQuery (UI): Detect checking of a checkboxjQuery(UI):检测复选框的检查
【发布时间】:2010-06-21 13:54:42
【问题描述】:

当用户选中复选框时,如何让 jQuery 触发事件?

<input type="checkbox" id="test" name="test" /><label for="test">Check me</label>

我可以使用 .click 来做到这一点,尽管当用户选择复选框时这不起作用。我无法在 api 文档中或在谷歌搜索时找到这方面的信息。

干杯。

【问题讨论】:

    标签: javascript jquery forms jquery-ui javascript-events


    【解决方案1】:
    $('#test').bind('change', function(){
        if($(this).is(':checked')){
            // box was checked
        }
    });
    

    【讨论】:

      【解决方案2】:

      您正在寻找change event

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

      【讨论】:

        猜你喜欢
        • 2012-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-07
        • 2014-04-26
        • 2013-02-02
        • 2013-06-21
        • 1970-01-01
        相关资源
        最近更新 更多