私はログインフォームの送信を防ぐために、サーバーにクエリを行い、ユーザー名とパスワードを確認してから、ホームページ。私が経験したjQueryのプログラマだが、これに遭遇したことがないevent.preventDefault()jQuery Mobile .live()イベントでフォームの送信を妨げない
$("#login-form").live("submit", function(event) {
event.preventDefault();
$.mobile.changePage("main.html", {
transition: "fade"
});
});
:login.htmlとで
:app.jsで
<form id="login-form">
<input type="text" name="login-username" id="login-username" value="" placeholder="Username" />
<input type="password" name="login-password" id="login-password" value="" placeholder="Password" /><br />
<button id="cab-submit" type="submit" data-theme="a" data-inline="true">Log In</button>
</form>
はここに関連するコードです。 changePage()は機能しますが、フォームが送信された後にのみ、不必要なページの読み込みが行われます。
EDIT:解決策が見つかりました。
フォーム提出を自分で処理したい場合は、data-ajax = "false"をフォームに追加する必要がありました。これはうまくいった。
新しいマークアップ:
<form id="login-form" data-ajax="false">
<input type="text" name="login-username" id="login-username" value="" placeholder="Username" />
<input type="password" name="login-password" id="login-password" value="" placeholder="Password" /><br />
<button id="cab-submit" type="submit" data-theme="a" data-inline="true">Log In</button>
</form>
あなたはjQueryのモバイルのどのバージョンを使用していますか? –
jQuery Mobile 1.0b3。 –