JavaScript prompt() 関数を jQM ダイアログに置き換えようとしています。私の目標は、ユーザーに文字列の入力を求め、ユーザーが送信 (送信ボタンまたは入力) したときに、入力した文字列を使用して関数を実行することです。
詳細には、キャンセル ボタンと [x] でダイアログを閉じ、何もせずにページに戻るようにします。送信ボタンで #strAccount 値を関数に渡すようにします。これは、フォームなどを使用しなくても簡単に実行できます。ただし、ユーザーが #strAccount フィールド内で Enter キーを押すこともできるようにしたいと考えています。これを行う最も簡単な方法はフォームにすることだと思いました。
フォームの送信時に false を返す必要があることがわかりました。ただし、それをすべて行うと、ページがリロードされますが、これは望ましくありません。
メインページのコンテンツの一部を次に示します。
<div id="NewEntry" data-role="page" data-title="New Time Entry">
<h3>Timesheet </h3>
<a id="openDialog" data-rel="dialog">Get account name...</a>
</div>
ダイアログは次のとおりです。
<div id="accountEntry" data-role="dialog">
<div data-role="header">
<h1>Filter by Account Name</h1>
</div>
<div data-role="content">
<form id="acctNameFilter" data-rel="back" data-ajax="false">
<p>Enter two or more letters from any part of the account name below:</p>
<input type="text" id="strAccount" placeholder="Enter any part of account name" autocomplete="off">
<a href="#NewEntry" data-role="button" data-rel="back" data-icon="delete" data-inline="true">Cancel</a>
<input type="submit" data-theme="b" data-icon="check" data-inline="true" value="Submit">
</form>
</div>
</div>
ここに私のページスクリプトがあります:
$(document).ready(function()
{
alert('page loading...'); //alert me if page reloads
$('#acctNameFilter').submit(function()
{
alert($('#strAccount').val()); //did it get passed?
getAcctsByString($('#strAccount').val()); //the function I want to run
$('#strAccount').val(''); //clear out the dialog's value... (necessary?)
$('#accountEntry').dialog('close');
return false; //stop execution, I thought...
});
//#openDialog is a simple href link...
$('#openDialog').click(function()
{
$.mobile.changePage('#accountEntry',{changeHash: false});
});
}
#strAccount
あまり重要ではないもう 1 つの質問:ダイアログの読み込み後にフォーカスを設定するにはどうすればよいですか? ユーザーのプレスを最小限に抑えたい。
よろしくお願いします。