フォームの内容をJSON形式で取得するプラグイン「JSON Form」を紹介します。
jQueryプラグイン「JSON Form」
このプラグインを使えば、フォームに入力されたテキストや数字……などをJSON(ジェイソン、JavaScript Object Notation)形式で取得することができます。
また、JSON形式のデータをHTMLフォームに反映することもできます。
それではデモページをご覧ください。
「JSON Form」のデモ
デモのソース(HTML + jQuery)
<meta name="description" content="JSON Form のデモでーす。"> |
<title>JSON Form - jQueryプラグイン</title> |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> |
<script src="js/jquery.jsForm.js"></script> |
hobby: [{description:'食べ歩き'},{description:'散歩'},{description:'寝る'}] |
// links: [{href:'http://www.gargan.org',description:'Gargan.org'},{href:'http://www.github.com',description:'GitHub'}] |
$("#show").click(function() { |
alert(JSON.stringify($("#demo").jsForm("get"), null, " ")); |
<h1>JSON Form のデモです。</h1> |
<p>お名前: <input name="data.name"/></p> |
<p>年齢: <input name="data.age" class="number"/></p> |
<ul class="collection" data-field="data.hobby"> |
<li><input name="hobby.description"/> |
<button id="show">クリック!クリック!</button> |
jsファイルのダウンロード、オプション詳細はこちらからどうぞ。