jQuery Mobile PageContainer问题 [英] jquery mobile pageContainer issues
问题描述
如果我正确阅读了以下文档: http://jquerymobile .com/demos/1.1.0/docs/api/methods.html
If I am reading correctly the documentation on: http://jquerymobile.com/demos/1.1.0/docs/api/methods.html
使用pageContainer和role应该将一页的内容替换为当前页面,例如,好像它是保留页眉和页脚但仅更改内容的模板.
Using pageContainer and role should replace the contents of one page into my current page, for example as if it was a template where the header and footer are kept but only the contents are changed.
我正在尝试做一个简单的例子来理解它是如何工作的,但是我真是一团糟.
I am trying to do a simple example to understand how this works but I am having a hell of a time.
这是我超级简单的例子.
Here's my super simple example.
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="static/css/jquery.mobile-1.1.0.min.css" type="text/css" />
<script type="text/javascript" charset="utf-8" src="static/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="static/js/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.mobile.changePage('page2.html',{
'pageContainer': $('#content_container'),
'role':'content'
});
});
</script>
</head>
<body >
<div data-role="page">
<div data-theme="a" data-role="header">
<div data-role="navbar" data-iconpos="top">
My Header
</div>
</div>
<div id='content_container' data-role="content">
<p>Page 1 </p>
</div>
<div data-theme="a" data-role="footer">
My Footer
</div>
</div>
</body>
</html>
这是第2页
<html>
<body>
<div data-role="page">
<p>Page 2</p>
</div>
</body>
</html>
加载后,我没有将页面1"替换为页面2",而是被重定向到了一个新的空白页面.任何指出我做错事情的指针都将不胜感激.
When this loads, instead of replacing "Page 1" for "Page 2" I get redirected to a new empty page. Any pointers to what I am doing wrong would be appreciated.
推荐答案
这是通过API完成此操作的一种方法,不幸的是,直接利用jquery的加载并不能保持此方法的元素格式.
here's a way to accomplish this through the API, unfortunately utilizing jquery's load directly does not keep the format the elements this method however, does.
$(document).bind('pageload',function(evt,data){
$(document).unbind('pageload');
$(data.page).fadeIn();
});
$.mobile.loadPage('page2.html',{'pageContainer':$('#content_container')});
这篇关于jQuery Mobile PageContainer问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!