复选框更改事件未触发 [英] Checkbox change event not firing

查看:75
本文介绍了复选框更改事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<script>
  $(document).ready(function() {
    $('.chk').live('change', function() {
      alert('change event fired');
    });
    $('a').click(function() {
      $('.chk').attr('checked', true);
    });
  });
</script>
</head>
<body>
<div class="chkHolder">
  <input type="checkbox" class="chk" name="a" id="a" />
  <input type="checkbox" class="chk" name="b" id="b" />
</div>
<a href="#">check all</a>
</body>
</html>

当我单击全部检查"超链接时,我希望为每个复选框触发更改事件.但是,这没有发生.

When I click on the "check all" hyperlink, I want the change event fired for each of the checkboxes. However, that is not happening.

有什么想法吗?

非常感谢!

推荐答案

使用:$('.chk').attr('checked', true).change();

实时示例: http://jsfiddle.net/NRPSA/1/

这篇关于复选框更改事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆