.focusout()


.focusout( handler(eventObject) )返回: jQuery

描述: 将一个事件函数绑定到"focusout" 事件。

  • 添加的版本: 1.4.focusout( handler(eventObject) )

    • handler(eventObject)
      类型: Function()
      每次事件触发时会执行的函数。
  • 添加的版本: 1.4.3.focusout( [eventData ], handler(eventObject) )

    • eventData
      类型: Object
      一个对象,它包含的数据键值对映射将被传递给事件处理程序。
    • handler(eventObject)
      类型: Function()
      每次事件触发时会执行的函数。

当传递参数时,这个方法是 .on('focusout', handler) 的快捷方式,当不传递参数的时候,是.trigger('focusout') 的快捷方式。

focusout 事件会在元素(或者其内部的任何元素)失去焦点时触发。这跟 blur 事件的显著区别在于,它可以在父元素上检测子元素失去焦点的情况(换而言之,它支持事件冒泡)。

这个事件通常会跟 focusin 事件一起使用。

例子:

监视段落内部失去焦点的情况。请注意 focusout 计数和 blur 计数的差异。

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html>
<head>
<style>
.inputs { float: left; margin-right: 1em; }
.inputs p { margin-top: 0; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div class="inputs">
<p>
<input type="text" /><br />
<input type="text" />
</p>
<p>
<input type="password" />
</p>
</div>
<div id="fo">focusout fire</div>
<div id="b">blur fire</div>
<script>
var fo = 0, b = 0;
$("p").focusout(function() {
fo++;
$("#fo")
.text("focusout fired: " + fo + "x");
}).blur(function() {
b++;
$("#b")
.text("blur fired: " + b + "x");
});
</script>
</body>
</html>

Demo: