<div data-role="fieldcontain">data-role="fieldcontain"という属性は、フォームなどの項目を示すためのものです。これを記述することで、1つ1つの項目を整理し表示することができます。表示されたGUIを見ると、入力フィールドとボタンの間にラインが引かれているのが分かるでしょう。複数のGUI項目を用意する際には、このようにしてデザインを整理することができます。
<label for="input1">input:</label>
<input type="text" name="input1" id="input1" />
</div>
var input = $('#input1').val();$('#○○')というのは、jQueryのショートカット関数です。jQueryでは、このように$()の引数にタグのIDを指定することで、そのタグを操作するためのオブジェクトを簡単に作成できます。このタグのvalue属性はval()で、またinnerHTMLでテキストを設定する場合はtext()で、それぞれアクセスできます。非常にシンプルでいいでしょう?
$('#dlog_content').text('あなたは、"' + input + '"と書きました。');
$.mobile.changePage("#dialog", {transition: "pop"});そして、これがダイアログを表示している部分です。jQuery Mobileの機能は、$.mobileというオブジェクトの中にまとめられています。そして「changePage」というメソッドが、表示切替を行うためのものになります。これは以下のように引数を指定します。
changePage( 移動先 , オプション設定 );移動先――新たに表示するページやダイアログのIDを指定します。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>Sample</title> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> <script type="text/javascript"> function doAction(){ var input = $('#input1').val(); $('#dlog_content').text('あなたは、"' + input + '"と書きました。'); $.mobile.changePage("#dialog", {transition: "pop"}); } </script> </head> <body> <div id="home" data-role="page"> <div data-role="header"> <h1>Hello</h1> </div> <div data-role="content"> <p>jQuery Mobileサンプル。</p> <div data-role="fieldcontain"> <label for="input1">input:</label> <input type="text" name="input1" id="input1" /> </div> <input type="button" value="Click" onclick="doAction();" /> </div> </div> <div id="dialog" data-role="dialog"> <div data-role="header"> <h1 id="dlog_title">Message</h1> </div> <div data-role="content"> <p id="dlog_content">コンテンツ。</p> </div> </div> </body> </html>
<< 前へ | 次へ >> |