Javascript 模糊与焦点 - 有什么真正的区别吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8973532/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 08:16:29  来源:igfitidea点击:

blur vs focusout -- any real differences?

javascriptjquery

提问by Laguna

Is there any difference between JS events blurvs focusout?

JS events blurfocusout之间有什么区别吗?

I have two textboxes: pwd and confirm pwd. I want to check password match when user tabs out of the confirm pwd textbox, for example. In this case which event should I use or does it matter?

我有两个文本框:密码和确认密码。例如,当用户跳出确认密码文本框时,我想检查密码匹配。在这种情况下,我应该使用哪个事件或者它重要吗?

回答by Frédéric Hamidi

The documentation for focusoutsays (emphasismine):

focusout的文档说(强调我的):

The focusoutevent is sent to an element when it, or any element inside of it, loses focus. This is distinct from the blurevent in that it supports detecting the loss of focus on descendant elements(in other words, it supports event bubbling).

focusout元素或其中的任何元素失去焦点时,该事件将发送到该元素。这与blur事件的不同之处在于它支持检测对后代元素的焦点丢失(换句话说,它支持事件冒泡)。

The same distinction exists between the focusinand focusevents.

focusinfocus事件之间也存在相同的区别。

回答by nulltoken

As stated in the JQuery documentation

JQuery 文档中所述

The focusout event is sent to an element when it, or any element inside of it, loses focus. This is distinct from the blur event in that it supports detecting the loss of focus on descendant elements (in other words, it supports event bubbling).

当元素或其中的任何元素失去焦点时,focusout 事件会发送到该元素。这与 blur 事件不同,因为它支持检测后代元素的焦点丢失(换句话说,它支持事件冒泡)。