被遗忘的HTML标签

虽然经常接触HTML,不过有些标签以前却从没引起我的注意。但是其中几个Tag的确比较有用,而且是符合W3C XHTML标准的。

1. Label
Label是用来标记Input元素的提示的。例如:
[code]
<label for="id_name">Name</label><br />
<input type="text" name="name" id="id_name" size="20"/>
[/code]
Label的"For"属性要和Input元素的ID相一致。
好处:点击提示文字,就自动Focus对应的输入元素。对于Radio,Checkbox这类点击区域特别小的控件特别有用:
[code]
Color:<br />
<input type="checkbox" name="color" id="color_r" value="red">
<label for="color_r"> red</label><br>
<input type="checkbox" name="color" id="color_g" value="green">
<label for="color_g"> green</label><br>
<input type="checkbox" name="color" id="color_b" value="blue">
<label for="color_x"> blue</label><br><!--如果For和ID不匹 配,点击文字是没有用的-->
[/code]

2. FieldSet & Legend

FieldSet用来明确把一组Input控件归成一组(相当于VB/VC里面的Group控件),而Legend则是组的标题(相当于Group控件的标题)。
例如:
[code]
<fieldset style="width:20%">
<legend>Person</legend>
<label for="name">Name</label><input type="text" id="name" />
<fieldset>
<legend>Gender</legend>
<input type="radio" name="gender" id="male" />
<label for="male">Male</label><br>
<input type="radio" name="gender" id="female" />
<label for="female">Female</label>
</fieldset>
</fieldset>
[/code]

3. Optgroup
用于Select里面的option的分组。例如:
[code]
<select name="age">
<optgroup label="baby">
<option>0-2</option>
<option>3-5</option>
</optgroup>
<optgroup label="kid">
<option>6-10</option>
<option>10-15</option>
</optgroup>
<optgroup label="adult">
<option>16-30</option>
<option>31-40</option>
<option>41-60</option>
</optgroup>
</select>
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值