Form : Input type and Label

2020/09/08

 

ShimoMeguro_下目黒

フォームの書き方:ラベルとインプットタイプをセットで記入する。
 ■ラベル:インプットする場所の見出しになる
 ■インプットタイプ:データ型を決め、箱を作る

<form>
 <label for="fname">First name:</label><br>
 <input type="text" id="fname" name="fname"><br>
  <label for="lname">Last name:</label><br>
 <input type="text" id="lname" name="lname">
</form>

インプットタイプは以下がある。デフォルトの入力文字制限は20文字。

  • <input type="button">
    書き方
    <form>
      <input type="radio" id="male" name="gender" value="male">
      <label for="male">Male</label><br>
      <input type="radio" id="female" name="gender" value="female">
      <label for="female">Female</label><br>
      <input type="radio" id="other" name="gender" value="other">
      <label for="other">Other</label>
    </form>

     
  • <input type="checkbox">
    書き方

    <form>
      <input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
      <label for="vehicle1"> I have a bike</label><br>
      <input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
      <label for="vehicle2"> I have a car</label><br>
      <input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
      <label for="vehicle3"> I have a boat</label>
    </form>

     
  • <input type="color">
  • <input type="date">
  • <input type="datetime-local">
  • <input type="email">
  • <input type="file">
  • <input type="hidden">
  • <input type="image">
  • <input type="month">
  • <input type="number">
  • <input type="password">
  • <input type="radio">
  • <input type="range">
  • <input type="reset">
  • <input type="search">
  • <input type="submit">
  • <input type="tel">
  • <input type="text"> "text"がinput typeのデフォルト
  • <input type="time">
  • <input type="url">
  • <input type="week">