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