jQuery Mobile フォーム入力要素


jQuery Mobile テキスト入力ボックス

入力フィールドは標準のHTML要素でコーディングされており、jQuery Mobile はそれらにスタイルを追加して、より魅力的に見せ、モバイルデバイスでより使いやすくします。新しい HTML5 の <input> タイプも使用できます。

例

<form method="post" action="demo_form.php">
<div class="ui-field-contain">
<label for="fullname">氏名:</label>
<input type="text" name="fullname" id="fullname">

<label for="bday">誕生日:</label>
<input type="date" name="bday" id="bday">

<label for="email">E-mail:</label>
<input type="email" name="email" id="email" placeholder="あなたのメールアドレス..">
</div>
</form>

試してみる »

ヒント:入力フィールドの期待値を説明する短い説明を指定するには、placeholder を使用してください:

<input placeholder="sometext">

テキストエリア

複数行のテキスト入力には <textarea> を使用できます。

注意:テキストを入力すると、テキストエリアは新しい行に合わせて自動的にサイズが調整されます。

例

<form method="post" action="demo_form.php">
<div class="ui-field-contain">
<label for="info">追加情報:</label>
<textarea name="addinfo" id="info"></textarea>
</div>
</form>

試してみる »


検索入力ボックス

type="search" タイプの入力ボックスは HTML5 で新しく追加されたもので、検索を入力するためのテキストフィールドを定義します。

例

<form method="post" action="demo_form.php">
<div class="ui-field-contain">
<label for="search">検索:</label>
<input type="search" name="search" id="search">
</div>
</form>

試してみる »


ラジオボタン

ユーザーが限られた数の選択肢から1つのオプションだけを選択する場合は、ラジオボタンを使用します。

一連のラジオボタンを作成するには、type="radio" の input と対応する label を追加します。ラジオボタンを <fieldset> 要素で囲みます。<fieldset> の見出しを定義するために <legend> 要素を追加することもできます。

ヒント:ボタンをグループ化するには、data-role="controlgroup" を使用してください:

例

<form method="post" action="demo_form.php">
<fieldset data-role="controlgroup">
<legend>Choose your gender:</legend>
<label for="male">Male</label>
<input type="radio" name="gender" id="male" value="male">
<label for="female">Female</label>
<input type="radio" name="gender" id="female" value="female">
</fieldset>
</form>

試してみる »


チェックボックス

ユーザーが限られた数の選択肢から1つまたは複数のオプションを選択する場合は、チェックボックスを使用します:

例

<form method="post" action="demo_form.php">
<fieldset data-role="controlgroup">
<legend>Choose as many favorite colors as you'd like:</legend>
<label for="red">Red</label>
<input type="checkbox" name="favcolor" id="red" value="red">
<label for="green">Green</label>
<input type="checkbox" name="favcolor" id="green" value="green">
<label for="blue">Blue</label>
<input type="checkbox" name="favcolor" id="blue" value="blue">
</fieldset>
</form>

試してみる »


实例

その他の例

ラジオボタンやチェックボックスを水平にグループ化するには、data-type="horizontal" を使用してください:

例

<fieldset data-role="controlgroup" data-type="horizontal">

試してみる »

<fieldset> を field コンテナで囲むこともできます:

例

<div class="ui-field-contain">
<fieldset data-role="controlgroup">
<legend>性別を選択してください:</legend>
</fieldset>
</div>

試してみる »

ボタンの1つをあらかじめ選択しておきたい場合は、HTML の <input> の checked 属性を使用してください:

例

<input type="radio" checked>
<input type="checkbox" checked>

試してみる »

フォームをポップアップに入れることができます:

例

<a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline">Show Popup Form</a>

<div data-role="popup" id="myPopup" class="ui-content">
  <form method="post" action="demoform.php">
    <div>
<h3>ログイン情報</h3>
<label for="usrnm" class="ui-hidden-accessible">ユーザー名:</label>
<input type="text" name="user" id="usrnm" placeholder="ユーザー名">
<label for="pswd" class="ui-hidden-accessible">パスワード:</label>
<input type="password" name="passw" id="pswd" placeholder="パスワード">
    </div>
  </form>
</div>

試してみる »
その他の拡張