6.9.8 帮助文本

6.9.8 帮助文本

帮助文本用于向用户提供额外的帮助信息,帮助用户理解某个文本框的具体功能。可通过如下CSS样式定义帮助文本。
.help-block:定义块级帮助文本。

此外,应通过aria-describedby 属性帮助文本表单控件进行关联,这样当用户将焦点定位到该控件或正在该控件中输入时,辅助技术(如屏幕阅读器)就会自动朗读这段帮助文本的内容。

程序示例

下面是帮助文本的示例。

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
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> 帮助文本 </title>
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css">
</head>

<body>
<div class="container">
<form action="http://www.fkit.org">
<div class="form-group">
<label for="name">用户名</label>
<!-- 使用aria-describedby属性关联帮助文本 -->
<input type="text" id="name" name="name" class="form-control" aria-describedby="helpBlock">
<!-- 定义帮助文本 -->
<span id="helpBlock" class="help-block">请输入你喜欢的用户名字</span>
</div>
</form>
</div>
<script type="text/javascript" src="../jquery-3.1.1.js"></script>
<script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
</body>

</html>