jQuery live方法有什么问题? [英] What's wrong with the jQuery live method?

查看:73
本文介绍了jQuery live方法有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery 1.7中已弃用 live() 方法. jQuery文档现在推荐

The live() method was deprecated in jQuery 1.7. The jQuery docs now recommend

使用.on()附加事件处理程序.较旧版本的jQuery的用户应优先使用.delegate()而不是.live().

Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().

我了解ondelegate的工作方式,但是我不明白为什么它们更好. live()更简单易用.

I understand how on and delegate work, but I don't understand why they are better. live() is simpler and easier to use.

不推荐使用live的原因吗?其他方法如何更好?如果我继续使用live,会发生什么不好的事情吗?

Is there a reason why live was deprecated? How are the other methods better? Will anything bad happen if I continue to use live?

推荐答案

在此处查看一些说明:

<罢工> http://www.ultimatewebtips.com/why-jquery-live-is-a-bad-option-to-use/ (站点似乎已关闭)

http://www.ultimatewebtips.com/why-jquery-live-is-a-bad-option-to-use/ (Site appears to be down)

报价:

  1. 您不能将.live()用于可重复使用的小部件.

  1. You can’t use .live() for reusable widgets.

.stopPropagation()不能实时使用.

.live()较慢.

.live()不可链接.

进一步的优点是.on()可以很好地简化所有事件: http://api.jquery.com/on/

Further beauty of .on() is that it streamlines all events quite well: http://api.jquery.com/on/

您知道api链接并了解.on()的工作原理:)

D'uh you know about the api link and see how .on() works :)

报价:

.on()方法将事件处理程序附加到当前选定的集合 jQuery对象中的元素的集合.从jQuery 1.7开始,.on()方法 提供附加事件处理程序所需的所有功能.为了 从旧版jQuery事件方法转换的帮助,请参见.bind(), .delegate()和.live().要删除与.on()绑定的事件,请参见 .离开().附加仅运行一次然后删除的事件 本身,请参阅.one()

The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers. For help in converting from older jQuery event methods, see .bind(), .delegate(), and .live(). To remove events bound with .on(), see .off(). To attach an event that runs only once and then removes itself, see .one()

这篇关于jQuery live方法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆