本文转自: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>
<metacharset="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.

最新文章

  1. python学习总结03
  2. iOS AFNetWorking 下载pdf文档
  3. C# 调用百度地图Web服务API
  4. centos6.5适用的国内yum源:网易、搜狐
  5. Oracle中的AS和IS
  6. 关于PHP开发的9条建议
  7. 配置SSH免密码验证
  8. 一些我后写出来的awk脚本
  9. pandas数据结构练习题(部分)
  10. Python基础学习参考(四):条件与循环
  11. 作业02-Java基本语法与类库
  12. Unable to find CMake in android studio
  13. react项目,build以后启动问题
  14. mongoDB实现MapReduce
  15. C# redis简单的使用
  16. thinkphp 随笔
  17. Ubuntu package system is broken
  18. 20145101《Java程序设计》第6周学习总结
  19. golang martini 源码阅读笔记之martini核心
  20. Java并发编程原理与实战三十二:ForkJoin框架详解

热门文章

  1. WordCount程序及测试
  2. Java流机制详解
  3. Python中的切片操作
  4. Chrome Plugin Recommendation
  5. lua遍历文件
  6. SharpCompress压缩和解压缩,并解决压缩的中文乱码问题
  7. c语言常使用的函数,见到一个记一个
  8. javascript 获取标签内的内容
  9. 内容可循环重用的ScrollView
  10. H - the Sum of Cube(水题)