admin管理员组文章数量:1332395
I was going through the history of dropdown.js in bootstrap and came across the following change History file on git, here:
$this.focus() // focus() being changed to trigger('focus');
$this.trigger('focus')
Now, the guy here has left a ment about the change saying:
Makes life for people with custom jQuery builds excluding event aliases much easier.
I don't quite understand what's the difference here between using focus()
or trigger('focus')
, as for me both have the same effect; why has the author chosen such a change?
I was going through the history of dropdown.js in bootstrap and came across the following change History file on git, here:
$this.focus() // focus() being changed to trigger('focus');
$this.trigger('focus')
Now, the guy here has left a ment about the change saying:
Makes life for people with custom jQuery builds excluding event aliases much easier.
I don't quite understand what's the difference here between using focus()
or trigger('focus')
, as for me both have the same effect; why has the author chosen such a change?
- 3 huh , why the downvote ?? – Alexander Solonik Commented Apr 7, 2015 at 22:25
- i am here to spead love nd upvotes ... and brotherhood , haters gonna hate . – Alexander Solonik Commented Apr 7, 2015 at 22:34
2 Answers
Reset to default 6https://github./jquery/jquery#modules.
If you are making a custom jQuery build and exclude event/alias
module - you won't have shortcuts to events (e.g. .click()
, .focus()
, .ready()
, etc).
So you'll have to use .on('eventName', handler)
for event binding and consequently .trigger('eventName')
to trigger jQuery event.
People with custom jQuery builds could create or modify their own focus()
functions intended to do whatever they want. Imagine if you create your own focus()
which allows lot of parameters and chains multiple callback; it would be a mess when you bine its usage with the jQuery focus()
basic function.
When you use a trigger it's qute obvious you're going to trigger an action; in this case, to focus an element.
Beside of that, using the trigger()
functions makes the code a little easier to understand.
本文标签: javascriptWhy change from focus() to trigger(39focus39)Stack Overflow
版权声明:本文标题:javascript - Why change from focus() to trigger('focus')? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742283416a2446512.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论