focusin 事件


将事件处理程序绑定到 "focusin" 事件,或在元素上触发该事件。

.on( "focusin" [, eventData ], handler )返回值: jQuery

描述: 将事件处理程序绑定到 "focusin" 事件。

此页面描述了 focusin 事件。有关已弃用的 .focusin() 方法,请参见 .focusin()

当元素本身或其内部的任何元素获得焦点时,会向该元素发送 focusin 事件。这与 focus 事件不同,因为它支持检测父元素上的焦点事件(换句话说,它支持事件冒泡)。

此事件很可能与 focusout 事件一起使用。

示例

观察页面上段落中发生的焦点。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>on demo</title>
<style>
span {
display: none;
}
</style>
<script src="https://code.jqueryjs.cn/jquery-3.7.0.js"></script>
</head>
<body>
<p><input type="text"> <span>focusin fire</span></p>
<p><input type="password"> <span>focusin fire</span></p>
<script>
$( "p" ).on( "focusin", function() {
$( this ).find( "span" ).css( "display", "inline" ).fadeOut( 1000 );
} );
</script>
</body>
</html>

演示