我试图阻止登录表单提交,所以我可以查询服务器,验证用户名和密码,然后只能移动到主页。event.preventDefault()不会阻止表单提交jQuery Mobile .live()事件
下面是相关代码:
在login.html的:
<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>
在app.js:
$("#login-form").live("submit", function(event) {
event.preventDefault();
$.mobile.changePage("main.html", {
transition: "fade"
});
});
我是一个有经验的程序员的jQuery,但从来没有遇到这种。 changePage()确实有效,但只发生在表单提交后导致不必要的页面加载之后。
编辑:找到解决方案。
如果我想自己处理表单提交,我必须在表单中添加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 Mobile的您使用的是? –
jQuery Mobile 1.0b3。 –