labelタグ

HTMLのlabelタグは、チェックボックスやテキストフォームと関連付けるためのタグ。
特に押しにくいチェックボックスやラジオボタンでは、文字の部分を入力すると選択されことになるので便利。

記述方法は二種類

  • labelのfor属性に対象のidを記述する方法

  • labelタグで囲んじゃう方法

後者のほうはブラウザ(特にIE系)によっては、認識しないとかなんとか。
前者のほうが、idが必須なのでめんどいけど、離れたところでも関連付けるから、整形する上では便利かも。

ちなみに、ASP.NETでは、前者の方法ではinputタグのIDが自動で決まるので、<%タグを使用して下記のようにする。

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">