我知道 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/