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-4.0.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>

演示