【发布时间】:2014-05-20 02:32:33
【问题描述】:
如何在复选框上监听 change 事件而不触发其容器上的 click 事件?
<label><input type="checkbox"> Hello world</label>
我想对复选框的change 事件触发一个操作,但我不希望它冒泡到标签上的click 事件。
(function ($) {
$('input').change(function (v) {
v.stopPropagation();
});
$('label').click(function () {
alert('You should not see this message if you click the checkbox itself!');
});
})(jQuery);
有什么想法吗?谢谢!
【问题讨论】:
-
将
click事件绑定到停止传播的input。
标签: javascript jquery events stoppropagation event-propagation