jquery-mobile – 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()确实有效,但只有在表单提交后才会发生,这会导致不必要的页面加载。

编辑:找到解决方案。

如果我想处理自己提交的表单,我不得不将数据-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>

解决方法

回答我自己的问题如果我想处理自己提交的表单,我不得不将数据-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>

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...