我在 bootstrap 中查看 dropdown.js 的历史,并在 git 上发现了以下更改历史文件,here :
$this.focus() // focus() being changed to trigger('focus');
$this.trigger('focus')
现在,这里的人对更改发表了评论说:
Makes life for people with custom jQuery builds excluding event aliases much easier.
我不是很明白这里使用focus()
和trigger('focus')
有什么区别,对我来说都是一样的效果;为什么作者选择了这样的改变?
最佳答案
https://github.com/jquery/jquery#modules .
如果您正在构建自定义 jQuery 构建并排除 event/alias
模块 - 您将没有事件的快捷方式(例如 .click()
、 .focus()
、.ready()
等)。
因此您必须使用 .on('eventName', handler)
进行事件绑定(bind),然后使用 .trigger('eventName')
触发 jQuery 事件。
关于javascript - 为什么从 focus() 改为触发 ('focus' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29502394/