繁体   English   中英

在jQuery中绑定元素及其子元素

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM