[英]Bind element and its children in jQuery
我想将一个事件绑定到一个元素及其子元素。 做这个的最好方式是什么?
$(element).bind('click', function(event) {
doSomething();
});
$(element).bind('click', function(event) {
doSomething();
}).children().bind("click",function(event){
// code to handle children click here
event.stopPropagation(); // if you don't want event to bubble up
});
你拥有的代码就是这样做的。
查看事件的target
字段以找出哪个实际子节点看到了该事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.