jquery - jquery 中的 delegate() 与 on() ?

标签 jquery

我知道 delegate() and on() 之间的区别,但我怀疑on()很受欢迎,速度比 delegate() 快那么为什么 jquery 不从其库中删除 delegate()

live()有缺点,然后从 jQuery-1.9 版本中删除它。 另外,如果我们看到 performance between on() and delegate()那么 on()delegate() 快得多。

那么有什么理由将 delegate() 保留在 jQuery 中呢?

最佳答案

这是 jQuery 团队成员写的 in regard to this issue 2013年:

"We haven't deprecated .bind or .delegate, nor have we indicated we're removing them at any point.

They're each only one line in the source so size reduction isn't much of a reason to remove them.

We deprecated .live because it has lots of confusing issues that we can't fix."

基本上,虽然 delegate() 已被 on() 取代,但 future 没有计划弃用 delegate(),因为事实上它占用的空间很小(并且不会引起任何问题)。

关于jquery - jquery 中的 delegate() 与 on() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22904904/

相关文章:

javascript - 将 JSON ID 键插入 ng-click 指令,然后将其传递给另一个 Controller

带有 hasClass 的 jQuery Iframe 内容

javascript - 是否可以使用 Jquery 在 HTML 中添加文本或 html 标签?

javascript - SimpleModal 关闭对话框前确认

javascript - jQuery:无法获取单选按钮值

javascript - 如何让 Angular 在 jqLit​​e 上使用 jQuery

javascript - 在 Bootstrap 表单/页面底部添加填充/空间

javascript - 如何在 diff 文本区域中显示 php 获取的值?

javascript - 如何检测数据表插件中的右键单击

javascript - div 被 youtube 嵌入覆盖,我该如何解决?