小强的HTML5移动开发之路(47)——jquery mobile基本的页面框架

一、单容器页面结构

<!DOCTYPE html> 
<html>
<head>
<title>Jquery mobile 基本页面框架</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="css/jquery.mobile-1.3.2.min.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
</head>
<body>
	<div data-role="page">
    	<div data-role="header">
        	<h1>标题</h1>
        </div>
        <div data-role="content">
        	<p>内容部分</p>
        </div>
        <div data-role="footer">
        	<h4>页脚</h4>
        </div>
    </div>
</body>
</html>
说明:<meta name="viewport" content="width=device-width,initial-scale=1">设置浏览器的缩放宽度与等级,可以使页面的宽度与移动设备的屏幕宽度相同。

二、多容器页面结构

<!DOCTYPE html> 
<html>
<head>
<title>Jquery mobile 基本页面框架</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="css/jquery.mobile-1.3.2.min.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
</head>
<body>
	<div data-role="page" id="p1">
    	<div data-role="header">
        	<h1>标题</h1>
        </div>
        <div data-role="content">
        	<p>内容部分</p>
            <a href="#p2">下一页</a>
        </div>
        <div data-role="footer">
        	<h4>页脚</h4>
        </div>
    </div>
   	<div data-role="page" id="p2" data-add-back-btn="true">
    	<div data-role="header">
        	<h1>标题</h1>
        </div>
        <div data-role="content">
        	<p>内容部分</p>
        </div>
        <div data-role="footer">
        	<h4>页脚</h4>
        </div>
    </div>
</body>
</html>
说明:data-add-back-btn属性表示是否在容器的左上角添加一个“回退”按钮,默认值为false.

另外给<a>元素添加data-rel属性也可以实现回退。

三、外部页面链接切换

<!DOCTYPE html> 
<html>
<head>
<title>Jquery mobile 基本页面框架</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="css/jquery.mobile-1.3.2.min.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
</head>
<body>
	<div data-role="page" id="p1">
    	<div data-role="header">
        	<h1>标题</h1>
        </div>
        <div data-role="content">
        	<p>内容部分</p>
            <a href="#p2">下一页</a>
        </div>
        <div data-role="footer">
        	<h4>页脚</h4>
        </div>
    </div>
   	<div data-role="page" id="p2" data-add-back-btn="true">
    	<div data-role="header">
        	<h1>标题</h1>
        </div>
        <div data-role="content">
        	<em style="float:right;padding-right:5px">
            	<a href="about.htm">访问外部页面</a>
            </em>
        </div>
        <div data-role="footer">
        	<h4>页脚</h4>
        </div>
    </div>
</body>
</html>
<!DOCTYPE html> 
<html>
<head>
<title>Jquery mobile 基本页面框架</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="css/jquery.mobile-1.3.2.min.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.mobile-1.3.2.min.js" type="text/javascript"></script>
</head>
<body>
	<div data-role="page" data-add-back-btn="true">
    	<div data-role="header">
        	<h1>外部页面</h1>
        </div>
        <div data-role="content">
        	你好,感谢你的关注
        </div>
        <div data-role="footer">
        	<h1></h1>
        </div>
    </div>
</body>
</html>
如果不想以ajax方式打开页面,在链接元素中添加rel="external"

四、预加载与页面缓存

        <div data-role="content">
        	<em style="float:right;padding-right:5px">
            	<a href="about.htm" data-prefetch="true">访问外部页面</a>
            </em>
        </div>
使用页面缓存功能将会使DOM内容变大,一旦选择了缓存功能,要及时清理。

将page容器的data-dom-cache设置为true,可以将该页面的内容注入文档的缓存中,或者通过js代码设置一个全局的属性,代码如下:

$(function(){
    $.mobile.page.prototype.options.domCache = true;
})


  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值