年月を入力するためのコントロールを作るには?
input type="month"タグの書式
input type="month"タグに対応しているブラウザ
※Windows 7上で動作確認を行っています。
※ブラウザの設定より、異なる挙動をする場合があります。
input type="month"タグの属性一覧
属性 | 内容 |
グローバル属性 | ※グローバル属性のページを参照してください。 |
指定可能なフォーム部品の共通属性 | name、disabled、form、autocomplete、autofocus、list、min、max、step、readonly、required、value ※フォーム部品の共通属性のページを参照してください。 |
input type="month"タグの解説
<input>タグは、入力コントロールを表す要素です。
<input>要素の「type」属性に「month」を指定すると、年月を入力するコントロールを作ることができます。
なお、実際には「2011-12」のような文字列がサーバー側に送信されます。
input type="month"タグのサンプルソース1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル1</title>
</head>
<body>
<section>
<h1>映画祭</h1>
<p>今年度の一番お気に入りの映画を教えてください。</p>
<form action="sample.cgi" method="post">
<p><label>映画タイトル:<input name="n"></label></p>
<p><label>映画を鑑賞した月:<input type="month" name="month"></label></p>
<p><input type="submit" value="送信"></p>
</form>
</section>
</body>
</html>
input type="month"タグのサンプル画面1
input type="month"タグのサンプルソース2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル2</title>
</head>
<body>
<header>
<h1>購読について</h1>
</header>
<p>購読を希望する方は下記お申込みフォームを記入し、送信してください。</p>
<form action="sample.cgi" method="post">
<fieldset>
<legend>お申込み</legend>
<p><label>お名前:<input name="n"></label></p>
<p><label>ご住所:<input name="adr" size="40"></label></p>
<p><label>購読開始ご希望月:<input type="month" name="month"></label></p>
<p><input type="submit" value="送信"></p>
</fieldset>
</form>
</body>
</html>
input type="month"タグのサンプル画面2
input type="month"タグの関連項目