jQuery Mobile - 如何将表单提交到URL并转移到DOM内的另一个页面?

tom*_*mmi 3 html jquery dom jquery-mobile

在jQuery移动示例中.提交表单后显示的页面与表单POST-ing/GET-ing的位置相同.

将表单提交到URL并转移到DOM内的另一个页面是否可行?

Jas*_*per 6

您可以submit为表单的事件添加事件处理程序并手动提交表单,然后手动转换到您想要的任何页面.

$(function () {
    $('#form_id').bind('submit', function (e) {
        e.preventDefault();
        $.post('path/to/file.php', $(this).serialize(), function (response) {
            $.mobile.changePage('#page_to_goto', {transition: 'slide'});
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

一些说明: