我喜欢 jQuery 1.3 中的新直播事件。我的问题是这次事件的表现。我知道使用 live 优于 click/bind('click'),但使用 live 优于 click/bind('click') 是否会影响性能?
如果不是,您为什么要使用 click 或 bind('click')?
最佳答案
If not, why would you ever use click or bind('click')?
因为 $.live()有一些明显的缺点
- Live events do not bubble in the traditional manner and
cannot be stopped using stopPropagation(This changed in jquery 1.4.4) or stopImmediatePropagation. For example, take the case of two click events - one bound to "li" and another "li a". Should a click occur on the inner anchor BOTH events will be triggered. This is because when a $("li").bind("click", fn); is bound you're actually saying "Whenever a click event occurs on an LI element - or inside an LI element - trigger this click event." To stop further processing for a live event, fn must return false.- Live events currently only work when used against a selector. For example, this would work: $("li a").live(...) but this would not: $("a", someElement).live(...) and neither would this: $("a").parent().live(...).
关于javascript - jQuery 的 .live ('click' , fn) 和 .click(fn) 之间的性能差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1368223/