Jquery mobile event.preventDefault()不阻止jQuery Mobile.live()事件上的表单提交

Jquery mobile event.preventDefault()不阻止jQuery Mobile.live()事件上的表单提交,jquery-mobile,Jquery Mobile,我试图阻止提交登录表单,以便查询服务器、验证用户名和密码,然后才能转到主页 以下是相关代码: 在login.html中: <form id="login-form"> <input type="text" name="login-username" id="login-username" value="" placeholder="Username" /> <input type="password"

我试图阻止提交登录表单,以便查询服务器、验证用户名和密码,然后才能转到主页

以下是相关代码:

在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>
我是一名经验丰富的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>
    <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>


登录
尝试将submit按钮上的id更改为id=“submit”,看看会发生什么。这似乎是jQuery mobile的一个已知问题。

回答了我自己的问题。如果我想自己处理表单提交,我必须将数据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>
    <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?对于遇到此问题的任何人,在事件处理程序中设置event.preventDefault()应该足以阻止表单提交,而不管是否设置了ajax表单;我正在使用jquery mobile 1.3.1是的,应该是。然而,它不适合我,我也在使用1.3.1。只有在添加数据ajax=“false”后,它才起作用。