javascript jQuery 中的 focusin/focusout 与 focus/blur 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10584042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between focusin/focusout vs focus/blur in jQuery?
提问by Rubens Mariuzzo
I was handling some events using the following code with jQuery 1.7.2:
我在jQuery 1.7.2 中使用以下代码处理一些事件:
$().on('focus blur', function(event) {
console.log(event.type);
});
And I have noticed that event.type
for both events, prints out: focusin
and focusout
.
而且我注意到,event.type
对于这两个事件,都会打印出:focusin
和focusout
。
What is difference between focusin/focusout
vs focus/blur
?
focusin/focusout
vs 和有什么不一样focus/blur
?
回答by gdoron is supporting Monica
Short answer: focusin
bubbles, focus
does not.
focusout
bubbles, blur
does not.
Read the docs:
简短的回答:focusin
泡沫,focus
没有。
focusout
泡沫,blur
没有。
阅读文档:
The focusin event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the focus event in that it supports detecting the focus event on parent elements (in other words, it supports event bubbling).
当元素或其中的任何元素获得焦点时,focusin 事件将发送到该元素。这与焦点事件的不同之处在于它支持检测父元素上的焦点事件(换句话说,它支持事件冒泡)。
回答by VisioN
From the docs:
从文档:
The focusin event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the focus event in that it supports detecting the focus event on parent elements (in other words, it supports event bubbling).
当元素或其中的任何元素获得焦点时,focusin 事件将发送到该元素。这与焦点事件的不同之处在于它支持检测父元素上的焦点事件(换句话说,它支持事件冒泡)。
And yes, you can find the same answer also here: Difference between the javascript/jQuery events "focus" and "focusin"?
是的,您也可以在这里找到相同的答案:javascript/jQuery 事件“focus”和“focusin”之间的区别?
回答by Sjoerd
The focusin event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the focus event in that it supports detecting the focus event on parent elements (in other words, it supports event bubbling).
当元素或其中的任何元素获得焦点时,focusin 事件将发送到该元素。这与焦点事件的不同之处在于它支持检测父元素上的焦点事件(换句话说,它支持事件冒泡)。