<label>标签for属性的妙用

<label>标签for属性的妙用在用户注册的时候,常常用户点击文字就需要将光标聚焦到对应的表单上面,这个是怎么实现的呢?就是下面我要介绍的标签的for属性定义:for属性规定label与哪个表单元素绑定 显式的联系:SocialSecurityNumber:隐式的联系:DateofBirth:> 下面是例子:无标题文档

在用户注册的时候,常常用户点击文字就需要将光标聚焦到对应的表单上面,这个是怎么实现的呢?就是下面我要介绍的<label>标签的for属性

定义:for 属性规定 label 与哪个表单元素绑定

 

<!--
显式的联系:
<label for="SSN">Social Security Number:</label>
<input type="text" name="SocSecNum" id="SSn" />

隐式的联系:
<label>Date of Birth: <input type="text" name="DofB" /></label>
-->	

下面是例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>
</head>
<body>
	
	<table>
		<tr>
			<td><label for="username">用户名:</label></td>
			<td><input type="text" name="username" id="username"></td>
		</tr>
		<tr>
			<td><label for="password">密码:</label></td>
			<td><input type="password" name="password" id="password"></td>
		</tr>
		<tr>
			<td><label for="repassword">密码确认:</label></td>
			<td><input type="password" name="repassword" id="repassword"></td>
		</tr>
		<tr>
			<td><label for="_basketball">爱好:</label></td>
			<td>
				<label><input type="checkbox" value="basketball" name="hobby" id="_basketball">basketball</label>
				<label><input type="checkbox" value="football" name="hobby" id="_football">football</label>
				<label><input type="checkbox" value="skating" name="hobby" id="_skating">skating</label>
				<label><input type="checkbox" value="dance" name="hobby" id="_dance">dance</label>
			</td>
		</tr>
		<tr>
			<td><label for="_boy">性别:</label></td>
			<td>
				<label><input type="radio" value="boy" name="sex" id="_boy">boy</label>
				<label><input type="radio" value="girl" name="sex">girl</label>
			</td>
		</tr>
		<tr>
			<td><label for="email">邮箱:<label></td>
			<td><input type="text" name="email" id="email"></td>
		</tr>
		<tr>
			<td><label for="address">住址:</label></td>
			<td><input type="text" name="address" id="address"></td>
		</tr>
	</table>
</body>
</html>

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/37142.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注