2014年9月17日 星期三

[HTML] The reason of using "for" attribute in "label" (label 內的 for 屬性用處)



用意是跟某 element 綁在一起。

比較常使用的方式是和 input 綁在一起,
點 label 時,就會讓 input 獲得 focus 。


寫法一 (使用 for )

<label for="inputId"> Input Here: </label>
<input id="inputId" type="text" />

寫法二 (wrap)

<label> Input Here:
  <input id="inputId" type="text" />
</label>

範例

用之前



用之後





沒有留言:

張貼留言