几个不太常用的HTML标记

王朝html/css/js·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

几个不太常用的HTML Tag ,看看大家有没有用得着的地方。

1. Label

Label是用来标记Input元素的提示的。Label的“For”属性要和Input元素的ID相一致。好处:点击提示文字,就自动Focus对应的输入元素。对于Radio,Checkbox这类点击区域特别小的控件特别有用:

Color:<br />

<input type="checkbox" name="color" id="color_r" value="red"><label for="color_r">&nbsp;red</label><br>

<input type="checkbox" name="color" id="color_g" value="green"><label for="color_g">&nbsp;green</label><br>

<input type="checkbox" name="color" id="color_b" value="blue"><label for="color_x">&nbsp;blue</label><br><!--如果For和ID不匹配,点击文字是没有用的-->

2. FieldSet & Legend

FieldSet用来明确把一组Input控件归成一组(相当于VB/VC里面的Group控件),而Legend则是组的标题(相当于Group控件的标题)。 例如:

<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>

3. Optgroup

用于Select里面的option的分组。例如:

<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>

备注:以上代码可以直接拷贝出生成一个html文件运行,测试效果。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航