TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Differences Between jQuery .bind() vs .live() vs .delegate() vs .on()

325 点作者 elijahmanor超过 13 年前

8 条评论

jd超过 13 年前
What I really like about the old style bind/live/delegate is that it's so grep-able. The new on()-based API makes it much harder to search through a codebase.<p>In addition, when you see something like:<p><pre><code> $('.table a').click(function() { ... } ) </code></pre> it immediately looks wrong, because there are probably multiple links in the table. Wrong code that looks wrong is great, because you can then refactor it as you come across it. But now you have to check if a second selector argument is passed to "on", to see if unnecessary event handlers are created.
评论 #3558464 未加载
评论 #3558511 未加载
emehrkay超过 13 年前
The more I use jQuery, the more of a mess I see that it is. Don't get me wrong, I'd rather use it than rolling my own cross browser solution, but it is not the library that Id choose first. I simply do not like the api choices, the lib works well, the api, as seen in this article, isn't too pretty.
评论 #3557642 未加载
评论 #3558183 未加载
评论 #3557718 未加载
评论 #3558159 未加载
评论 #3557666 未加载
评论 #3558035 未加载
bluesnowmonkey超过 13 年前
&#62; <i>The method attaches the same event handler to every matched element in the selection.</i><p>Why is that a con for .bind()? This used to be considered a performance <i>benefit</i> compared to onclick.
评论 #3558296 未加载
评论 #3560057 未加载
easymode超过 13 年前
I experienced this dilemma first hand. Thank you very much for explaining it clearly.
ars超过 13 年前
That html snippet at the top is quite strange - it's not legal to put an H3 or a P in an A.
评论 #3561168 未加载
wnoveno超过 13 年前
on a slightly less relevant note. is live() pronounced as live as in live wire or live as in die/live? we had a little debate going here on our office about this and we need closure dammit!
评论 #3560985 未加载
评论 #3560983 未加载
baddox超过 13 年前
I see "it's" used as the possessive pronoun so often and so deliberately by educated authors that the descriptive linguist in me is starting to think "its" has been deprecated. Still, the prescriptive linguist in me is repulsed.
blueprint超过 13 年前
Don't forget to check out livequery.<p><a href="http://docs.jquery.com/Plugins/livequery" rel="nofollow">http://docs.jquery.com/Plugins/livequery</a><p>"Live Query utilizes the power of jQuery selectors by binding events or firing callbacks for matched elements auto-magically, even after the page has been loaded and the DOM updated."<p>Oh so awesome.
评论 #3559165 未加载