javascript - jQuery 的 .live ('click' , fn) 和 .click(fn) 之间的性能差异

标签 javascript jquery events

我喜欢 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/

相关文章:

javascript - 如何从双向绑定(bind)表单输入控件访问先前的值?

javascript - 众所周知,单例是不好的做法, Angular 是基于单例的。 Angular 不好吗?

javascript - Google map 标记簇总和值

javascript - 使用 jquery 和 DOM 访问表单元素

javascript - 如何将JQuery easing 实现到这个窗口滚动移动功能中?

java - 业务事件框架

javascript - 在 javascript 中为所有事件类型定义回调函数

javascript - ScrollTop 转到错误的顶部

javascript - 在崩溃之前检测浏览器中的内存耗尽

javascript - Jquery 将文本字段的值插入到列表框中。?