zoukankan      html  css  js  c++  java
  • [转]jQuery Mobile: Get data passed to page via changePage mobile.changePage

    本文转自:http://stackoverflow.com/questions/15840611/jquery-mobile-get-data-passed-to-page-via-changepage

    Solution

    Send them like this:

    $.mobile.changePage('page2.html',{ dataUrl :"page2.html?parameter=123", data :{'paremeter':'123'}, reloadPage :true, changeHash :true});

    And read them like this:

    $("#index").live('pagebeforeshow',function(event, data){var parameters = $(this).data("url").split("?")[1];;
        parameter = parameters.replace("parameter=","");  
        alert(parameter);});

    More examples can be found here: jQuery Mobile: document ready vs page events, just look for chapter: Data/Parameters manipulation between page transitions.

    Example:

    index.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta
    charset="utf-8"/>
    <metaname="viewport"content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <metaname="apple-mobile-web-app-capable"content="yes"/>
    <metaname="apple-mobile-web-app-status-bar-style"content="black"/>
    <title>
    </title>
    <link
    rel="stylesheet"href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"/>
    <script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script><script> $(document).on('pagebeforeshow',"#index",function(){ $(document).on('click',"#changePage",function(){ $.mobile.changePage('second.html',{ dataUrl :"second.html?paremeter=123", data :{'paremeter':'123'}, reloadPage :false, changeHash :true});});}); $(document).on('pagebeforeshow',"#second",function(){var parameters = $(this).data("url").split("?")[1];; parameter = parameters.replace("parameter=",""); alert(parameter);});</script></head><body><!-- Home --><divdata-role="page"id="index"><divdata-role="header"><h3> First Page </h3></div><divdata-role="content"><adata-role="button"id="changePage">Test</a></div><!--content--></div><!--page--></body></html>

    second.html

    <!DOCTYPE html><html><head><meta charset="utf-8"/>
    <meta
    name="viewport"content="widdiv=device-widdiv, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="apple-mobile-web-app-capable"content="yes"/>
    <meta
    name="apple-mobile-web-app-status-bar-style"content="black"/><title></title>
    <link
    rel="stylesheet"href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css"/>
    <script
    src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script></head>
    <body><!-- Home --><div data-role="page"id="second"><div data-role="header"><h3> Second Page </h3></div><divdata-role="content"></div><!--content--></div><!--page--></body></html>

    More info

    If you want to learn more about this topic take a look at this article. You will find several solutions with examples.

  • 相关阅读:
    [luogu4053 JSOI2007] 建筑抢修 (贪心 优先队列)
    [luogu2272 ZJOI2007] 最大半连通子图 (tarjan缩点 拓扑排序 dp)
    20180705 考试记录
    [luogu4310] 绝世好题 (递推)
    [luogu2765 网络流24题] 魔术球问题 (dinic最大流)
    [luogu4151 WC2011] 最大XOR和路径 (线性基)
    [luogu3232 HNOI2013] 游走 (高斯消元 期望)
    [luogu3726 HNOI2017] 抛硬币 (拓展lucas)
    20180703 考试记录
    [spoj] HIGH
  • 原文地址:https://www.cnblogs.com/freeliver54/p/3679003.html
Copyright © 2011-2022 走看看