雖然經(jīng)常接觸HTML,不過有些標(biāo)簽以前卻從沒引起我的注意。但是其中幾個(gè)Tag的確比較有用,而且是符合W3C XHTML標(biāo)準(zhǔn)的。
1. Label
Label是用來標(biāo)記Input元素的提示的。例如:
<label for="id_name">Name</label><br />
<input type="text" name="name" id="id_name" size="20"/>
Label的“For”屬性要和Input元素的ID相一致。
好處:點(diǎn)擊提示文字,就自動(dòng)Focus對(duì)應(yīng)的輸入元素。對(duì)于Radio,Checkbox這類點(diǎn)擊區(qū)域特別小的控件特別有用:
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不匹配,點(diǎn)擊文字是沒有用的-->
red
green
blue
2. FieldSet & Legend
FieldSet用來明確把一組Input控件歸成一組(相當(dāng)于VB/VC里面的Group控件),而Legend則是組的標(biāo)題(相當(dāng)于Group控件的標(biāo)題)。 例如:
<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>
PersonName GenderMale
Female
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>