在用户注册的时候,常常用户点击文字就需要将光标聚焦到对应的表单上面,这个是怎么实现的呢?就是下面我要介绍的<label>标签的for属性
定义:for 属性规定 label 与哪个表单元素绑定
[html] view plaincopy
- <!--
- 显式的联系:
- <label for="SSN">Social Security Number:</label>
- <input type="text" name="SocSecNum" id="SSn" />
- 隐式的联系:
- <label>Date of Birth: <input type="text" name="DofB" /></label>
- -->
下面是例子:
[html] view plaincopy
- <!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>
时间: 2024-12-19 04:17:12