LoginSignup
0
1

More than 3 years have passed since last update.

HTMLフォーム部品

Posted at
①valueで初期値を設定
<input type="text" value="hello">

②password入力用の部品で文字が伏字になる
<input type="password">

③placeholderで入力例を記載する
<input type="test" placeholder="住所">

④labelを付けてあげると、何を書くべきかが分かりやすくなる。
そして、for文とidで紐づけをきちんと行うと、labelをクリックしたときに、
inputタグにfocusがあたる。
また、HPなどの読み上げ機能の際には、紐づけしてあると名前が読み上げられる。

<label for="name">名前</label>
<input type="text" id="name">

下記のように略すこともできる
<label>名前<input type="text"></label>

⑤ドロップダウンリスト
size="2"を選択すると、2行分表示される
multipleは複数選択可能
selected属性は最初から項目指定ができる

<select size="2" multiple>
<option>1</option>
<option selected>2</option>
</select>

⑥チェックボックス
<input type="checkbox">andorid
<input type="checkbox">ipad

ラベルと紐づけすると、文字をタップしてもチェックされる
<label><input type="checkbox">iphone</label>

最初からチェックする
<input type="checkbox" checked>andorid

グループ化する(複数選択)
<fieldset>
<legend>携帯端末</legend>
<input type="checkbox">andorid
<input type="checkbox">ipad
</fieldset>

⑥ラジオボタン
ラジオボタンは、name属性で同じ項目の質問だよと
してあげないと複数選択できるようになってしまう。

<fieldset>
<legend>携帯端末</legend>
<input type="radio" name="phone">andorid
<input type="radio" name="phone">ipad
</fieldset>

⑦ボタンを押せなくする
<input type="button" disabled>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1