What is best way to perform jQuery .change()

北战南征 提交于 2019-11-28 00:00:39

Before jQuery 1.7, change() was simply a short cut for bind("change").

As of 1.7 however, on() was introduced, and is preferred to bind(). That now means change() is a shortcut for on("change"), and in fact all bind() calls will now call on() internally.

In short, they do the same thing. I find the explicit use of on() (or bind()) preferable, but as long as you're consistent throughout your code base, I don't see any real differences.

One could argue that using change() over on("change") is "better", as a typo in the word "change" would throw a parse error in the first instance ("undefined is not a function"), but would fail silently with on()... but obviously your unit tests would catch that, right? ;).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!