简体   繁体   English

jQuery移动表单数据在单个文件的两个页面之间提交?

[英]Jquery mobile form data submit between two pages in a single file?

I want send the data 'home_page' page to 'get_data' page.how to get the data from home page and send to the second page using jquery 我想将数据``首页''页面发送到``get_data''页面。如何从首页获取数据并使用jquery发送到第二页

<div class="main">
<!-- first page -->
    <section id="home_page" data-role="page">
        <header data-role="header">
            <h1>Header</h1>
        </header><!-- /header -->
        <article role="main" class="ui-content">
        <!-- Form -->
            <form action="" method="post" accept-charset="utf-8">
             form data send here            
            </form>
        </article><!-- /content -->
        <footer data-role="footer">
            <h1>Footer</h1>
        </footer><!-- /footer -->
    </section><!-- second page -->
    <section id="get_data" data-role="page">
        <header data-role="header">
            <h1>Header</h1>
        </header><!-- /header -->
        <article role="main" class="ui-content">
            <p> display the data here from home page </p>
        </article><!-- /content -->
        <footer data-role="footer">
            <h1>Footer</h1>
        </footer><!-- /footer -->
    </section><!-- /page -->
</div>

You can grab the form data on page 1 and append the form values to the 2nd page. 您可以在第1页上获取表单数据,并将表单值附加到第二页。 when that's done you can then change the page if you wish. 完成后,您可以根据需要更改页面。 In the demo, the Submit button goes to the 2nd page. 在演示中,“提交”按钮转到第二页。

code

$("#sub").on( "click", function( event ) {
var first = $('#first').val();
var last  = $('#last').val();

$("#formdata").empty();

var pagedata = $("<p>" + first + "</p><p>" + last + "</p>");    

pagedata.appendTo("#formdata");

$("#formdata").enhanceWithin();

$( ":mobile-pagecontainer" ).pagecontainer( "change", "#get_data", { transition: "pop" } );    
})

demo 演示

http://jsfiddle.net/j6btvLym/ http://jsfiddle.net/j6btvLym/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM