最近在公司做一个移动客户端,混合应用模式开发,使用的Jquerymobile,自己对jquerymobile不是很熟悉,利用空闲的时间从头开始学习jquerymobile。希望通过自己的努力,和记录能够使自己对于jquerymobile有一定的了解。
花了几分钟写了一个jquerymobile的最简单的页面,学习每个技术都是先写hello XX,所以我这次第一次写的是hello jquerymobile。代码如下:
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>第一个jquerymobile页面</title>
- <meta name="viewport" content="width=device-width,initial-scale=1" />
- <link rel="stylesheet" href="jqm/jquery.mobile-1.2.0.min.css"/>
- <script src="jqm/jquery-1.8.2.min.js"></script>
- <script src="jqm/jquery.mobile-1.2.0.min.js"></script>
- </head>
- <body>
- <div id="first" data-role="page">
- <div id="header" data-role="header">
- <h1>这是第一个jquerymobile页面</h1>
- </div>
- <div id="content" data-role="content">
- Hello Jquerymobile!!
- </div>
- <div id="footer" data-role="footer">
- <h4>Footer</h4>
- </div>
- </div>
- </body>
- </html>
这是一个很简单的页面,但是有几点需要说明。
在代码中使用的是本地下载的css、js,但是真正做网站的时候不建议这样,建议使用jquerymobile的CDN去加载文件,代码如下:
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
- <script src="http://code.jquery.com/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>
引用js的时候,一定要先写jquery然后再写jquerymobile,否则会出错。因为jquerymobile依赖jquery。
还有在head中的一段代码:
- <meta name="viewport" content="width=device-width,initial-scale=1" />
在代码中我们并没有对header和footer加什么样式,但是显示的结果是有样式的,这样的原因是jquerymobile自动为它们添加了样式。