:focusable Selector


focusable selector

Description: 选择可被聚焦的元素。

  • jQuery( ":focusable" )

一些元素本身是可聚焦的(focusable),而另一些元素需要显式设置 tab 索引。以上两种情况,为了可聚焦(focusable),元素都必须是可见的。

下面类型的元素如果未被禁用,则是可聚焦的(focusable):inputselecttextareabuttonobject。锚如果带有 hreftabindex 属性,则是可聚焦的(focusable)。area 元素如果在一个已命名的 map 内,且带有 href 属性,且有一个可见的图像使用了该 map,则是可聚焦的(focusable)。所有其他完全基于 tabindex 属性和可见度的元素是可聚焦的(focusable)。

注释:带有负的 tab 索引的元素是 :focusable,不是 :tabbable

Example:

选择可聚焦的元素,且用一个红色边框突出显示。

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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>focusable demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<style>
input, a, p {
border: 1px solid #000;
}
div {
padding: 5px;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
<div><input value="text input"></div>
<div><a>anchor without href</a></div>
<div><a href="#">anchor with href</a></div>
<div><p>paragraph without tabindex</p></div>
<div><p tabindex="1">paragraph with tabindex</p></div>
<script>
$( ":focusable" ).css( "border-color", "red" );
</script>
</body>
</html>

Demo: