`
fengpeng
  • 浏览: 99564 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

被遗忘的HTML标签

    博客分类:
  • Html
阅读更多
关键字:   html    

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

1. Label
Label是用来标记Input元素的提示的。例如:

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

 

2. FieldSet & Legend

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

代码
  1. <fieldset style="width:20%">  
  2.   <legend>Person</legend>  
  3.   <label for="name">Name</label><input type="text" id="name" />  
  4.   <fieldset>  
  5.     <legend>Gender</legend>  
  6.     <input type="radio" name="gender" id="male" />  
  7.     <label for="male">Male</label><br>  
  8.     <input type="radio" name="gender" id="female" />  
  9.     <label for="female">Female</label>  
  10.   </fieldset>  
  11. </fieldset>  
<script>render_code();</script>

 

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

代码
  1. <select name="age">  
  2.   <optgroup label="baby">  
  3.     <option>0-2</option>  
  4.     <option>3-5</option>  
  5.   </optgroup>  
  6.   <optgroup label="kid">  
  7.     <option>6-10</option>  
  8.     <option>10-15</option>  
  9.   </optgroup>  
  10.   <optgroup label="adult">  
  11.     <option>16-30</option>  
  12.     <option>31-40</option>  
  13.     <option>41-60</option>  
  14.   </optgroup>  
  15. </select>  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics