label标签为 input 元素定义标注(标记)。
label 元素不会向用户呈现任何特殊效果。不过,它为鼠标用户改进了可用性。
如果您在 label 元素内点击文本,就会触发此控件。
就是说,当用户选择该标签时,浏览器就会自动将焦点转到和标签相关的表单控件上。
标签的 for 属性应当与相关元素的 id 属性相同。
例1:
<pre class="brush:xml;"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>label 标签</title>
</head>
<body>
<form>
<p>
<label for="username">姓名:</label>
<input type="text" name="username" id="username" />
</p>
<p>
<label for="password">密码:</label>
<input type="password" name="password" id="password" />
</p>
</form>
</body>
</html>
```
<p>
例2:</p>
<pre class="brush:xml;"> !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>label 标签</title>
</head>
<body>
<form>
<p>
<input type="checkbox" name="temrs" id="temrs"/>
<lable for="temrs">这里是相关的协议</label>
</p>
</form>
</body>
</html>
```
label html