这篇文章是使用 jQuery Mobile 与 HTML5 开发 Web App 系列的第二篇,在本文以及接下来的数篇文章 Kayo 将会介绍 jQuery Mobile 的组件、事件响应以及可以调用的方法,而作为该系列的第一篇文章,Kayo 将会先介绍 jQuery Mobile 的基本情况和一些基础的实例。

一.jQuery Mobile 的渐进增强设计与浏览器支持

上一篇文章中, Kayo 简单介绍了渐进增强设计的概念,可以参考文中的第四点内容。而 jQuery Mobile 虽然是一些新 web 技术( HTML5、CSS3 和 JavaScript )的产物,但对于不能提供以上技术支持的设备也会尽量提供最好的体验。

根据维基百科( Wikipedia ) 的解释,渐进增强的设计主要包括以下几点

  • basic content should be accessible to all web browsers (所有浏览器都应能访问全部基础的内容)
  • basic functionality should be accessible to all web browsers (所有浏览器都应能访问全部基础的功能)
  • sparse, semantic markup contains all content (所有的内容应该在少量语义标签内)
  • enhanced layout is provided by externally linked CSS (增强的功能应该由外部 CSS 提供)
  • enhanced behavior is provided by unobtrusive, externally linked JavaScript (增强的行为由外部 JavaScript 提供 )
  • end-user web browser preferences are respected (终端用户的浏览器习惯应受尊重)

因为 jQuery Mobile 使用了渐进增强的设计理念,因而它所支持的系统与平台也很广泛,能提供 A 级支持(支持全部的增强的体验,包括基于 Ajax 的动画页面转场)的有以下平台:

Apple iOS 3.2-5.0

Android 2.1-2.3 , 3.1, 4.0

Windows Phone 7-7.5

Blackberry 6.0 , 7

Blackberry Playbook 1.0-2.0

Palm WebOS 1.4-2.0 , 3.0

Firebox Mobile (10 Beta)

Skyfire 4.1

Opera Mobile 11.5

Meego 1.2

Samsung bada 2.0

Kindle 3 and Fire

Nook Color 1.4.1

Chrome Desktop 11-17

Firefox Desktop 4-9

Internet Explorer 7-9

Opera Desktop 10-11

注:若在实际的开发中使用到 Web SQL Database 等 HTML5 技术,则最终的 Web App 被支持度会比以上 jQuery Mobile 的被支持度低,但两个主流的移动浏览器 Android 与 Apple iOS 的系统浏览器及其桌面版本肯定能提供最好的支持。

二.HTML5 data-* 属性

jQuery Mobile 依赖 HTML5 data-* 属性 来提供一系列的支持( UI 组件、过渡和页面结构),不支持该 HTML5 属性的浏览器会默认忽略这些属性的效果,比如在页面中添加一个版头,可以使用以下的 HTML:

1
2
3
<div data-role="header">
    <h1>jQuery Mobile Demo</h1>
</div>

这样就能产生一个 jQuery Mobile 样式的版头,从下文的图中可以看出,这样的版头样式很适合移动设备使用,并且在添加 data-role="header" 属性后,div 内的 h1 也会被渲染成一定样式,这就是 jQuery Mobile 的方便快捷,也是它的设计宗旨—— Write Less, Do More 。

除此之外 jQuery Mobile 中还有以下的 data-role 属性(部分属性),已经赋予了一定的样式及用户操作响应效果。

data-role="content" , data-role="button" , data-theme ="" , data-role="controlgroup" , data-inline="true" , data-role="fieldcontain" , data-role="listview" , data-rel="dialog" , data-transition="pop" ,分别对应着主体内容、按钮,主题颜色,已编辑按钮,内联按钮,表单元素,列表视图,对话框,页面过渡。

三.jQuery Mobile 基本使用方法

1.引入 jQuery Mobile

使用 jQuery Mobile ,需要在网页页眉中引入 jQuery Mobile 组件,包括以下部分

jQuery 库

jQuery Mobile CSS

jQuery Mobile 库

可以通过这样的 head 引入以上组件

1
2
3
4
5
6
7
8
<head>
    <title>jQuery Mobile Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>

2.加入 viewport

在 Android 的浏览器中,若没有设定页面宽度,它会认为页面宽度是 980px ,因此我们可以在 head 里加入一个 viewport,让移动浏览器知道屏幕大小,只是一个 viewport 标签,就已经给用户带来更好的体验。

1
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.5">

3.简单的页面实例

在引入 jQuery Mobile 需要的组件后,我们可以创建 jQuery Mobile 页面,下面给出一个简单的例子。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html>
<head>
    <title>jQuery Mobile Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
 
<body>
 
<div data-role="page" id="home">
 
    <div data-role="header">
        <h1>jQuery Mobile Demo</h1>
    </div>
 
    <div data-role="content">
        <p>主体内容</p>
    </div>
 
    <div data-role="footer">
        <h2>Footer</h2>
    </div>
 
</div>
 
</body>
</html>

对于 jQuery Mobile ,每定义一个 data-role="page" 就相当于一个页面, jQuery Mobile 默认采用 Ajax 的方式操作 DOM,自动隐藏除第一个页面外的所有页面,当点击链接,链接到其他页面时会以 Ajax 的方式加载新页面的内容,下面给出完整实例。另外,我们还可以使用一些 HTML5 的语义化标签,如 header 的 div 可以直接使用 header 标签,具体的可以参见下面的例子。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
    <title>jQuery Mobile Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
 
<body>
 
<div data-role="page" id="home">
 
    <header data-role="header">
        <h1>jQuery Mobile Demo</h1>
    </header>
 
    <div data-role="content">
        <a href="#page2" data-role="button">列表页面</a>
    </div>
 
    <footer data-role="footer">
        <h2>Footer</h2>
    </footer>
 
</div>
 
<div data-role="page" id="page2">
 
    <header data-role="header">
        <h1>jQuery Mobile Demo</h1>
    </header>
 
    <div data-role="content">
        <ul data-role="listview" data-inset="true">
            <li><a href="#home">回到首页</a></li>
            <li><a href="#home">回到首页</a></li>
            <li><a href="#home">回到首页</a></li>
        </ul>
    </div>
 
    <footer data-role="footer">
        <h2>Footer</h2>
    </footer>
 
</div>
 
</body>
</html>

完整实例 Demo(建议使用 PC 上的 Firefox、Chrome 等现代浏览器和 IE9+ 或 Android , iPhone/iPad 的系统浏览器浏览)

本文由 Kayo Lee 发表,本文链接:http://kayosite.com/web-app-by-jquery-mobile-and-html5-foundation.html

html5文章 -- 使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 基础的更多相关文章

  1. [转]使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 事件详解

    在前文<使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 默认配置与事件基础>中,Kayo 对 jQuery Mobile 事件的基 ...

  2. 使用 jQuery Mobile 与 HTML5 开发 Web App 系列文章目录

    使用 jQuery Mobile 与 HTML5 开发 Web App 系列文章目录 时间:2012年9月20日 分类:JavaScript 标签:HTML5‚ jQuery Mobile‚ Web ...

  3. html5文章 -- 使用 jQuery Mobile 与 HTML5 开发 Web App ——开发原则 | Kayo's Melody

    最近专注研究 jQuery Mobile —— 一款很方便就可以把 Web App 包装成适合 Android 与 iPhone 等触屏移动设备的 Javascript 库,结合 jQuery Mob ...

  4. 利用JQuery Mobile开发web app

    什么是web app web app 是基于web的应用程序,是针对移动设备优化后的web站点,它具有 开发成本低——采用web开发技术,不需要考虑跨平台以及底层适配问题: 升级简单——不需要通知用户 ...

  5. 亲手使用Sencha Touch + phonepag开发Web APP随笔 -- 第一个APP

    参考博文: [Phonegap+Sencha Touch] 移动开发1.准备工作 [Phonegap+Sencha Touch] 移动开发2.PhoneGap/Cordova初步使用   经过差不多1 ...

  6. 使用 jQuery Mobile 与 HTML5 开发 Web App —— HTML5 离线缓存

    本文要介绍的,是 HTML5 离线网络应用程序的特性,离线网络应用程序在 W3C 中的实际名称是 "Offline Web applications" ,也称离线缓存.当用户打开浏 ...

  7. 亲手使用Sencha Touch + phonepag开发Web APP随笔 -- 环境安装篇

    最近因为有个项目需要制作APP,考虑到需要兼容Android和IOS,所以想采用WebAPP的方式来开发.现在是从零开始学习之路,走起-   通过网上博客和论坛,开始安装了一堆软件: 1. Sench ...

  8. [资料分享]组件方式开发 Web App全站

  9. 搭建Cordova + Ionic + WebStorm环境开发Web App应用

    1. 下载并且安装Node.js(https://nodejs.org/en/) 2. 打开终端,安装cordova (如果安装失败或者卡住不动则重新安装)    sudo npm install - ...

随机推荐

  1. eclipse字体的设置

    eclipse的默认字体太小,所以设置的大一些比较清楚,方法很简单,单击菜单栏的"Window"选择"Preferences",如下图: 然后左侧依次选择Gen ...

  2. 现在, Delphi 的多线程已经非常易用了!

    先看一个非多线程的例子, 代码执行时不能进行其它操作(譬如拖动窗体): {自定义方法: 在窗体上绘制...} procedure MyMethod; var   i: Integer; begin   ...

  3. 重温CSS之背景、文本样式

    CSS背景样式: 背景色:background-color属性,设置元素的背景色,如:div {background:blue;}--设置所有div元素的背景为蓝色: 背景图像:background- ...

  4. 【python】继承时注意事项

    1. __init__ 注意事项 如果父类有__init__函数,子类没有,则子类自动调用父类__init__函数 如果父类有__init__函数,子类也有,则子类必须主动调用父类__init__函数 ...

  5. Fedora 启动sshd服务:

    .先确认是否已安装ssh服务: [root@localhost ~]# rpm -qa | grep openssh-server openssh-server-.3p1-.fc12.i686 (这行 ...

  6. EZ的间谍网络(codevs 4093)

    由于外国间谍的大量渗入,学校安全正处于高度的危机之中.YJY决定挺身而作出反抗.如果A间谍手中掌握着关于B间谍的犯罪证据,则称A可以揭发B.有些间谍收受贿赂,只要给他们一定数量的美元,他们就愿意交出手 ...

  7. Solr常用查询语法笔记

    1.常用查询 q - 查询字符串,这个是必须的.如果查询所有*:* ,根据指定字段查询(Name:张三 AND Address:北京) fq - (filter query)过虑查询,作用:在q查询符 ...

  8. hrbustoj 1545:基础数据结构——顺序表(2)(数据结构,顺序表的实现及基本操作,入门题)

    基础数据结构——顺序表(2) Time Limit: 1000 MS    Memory Limit: 10240 K Total Submit: 355(143 users) Total Accep ...

  9. Twitter search API

    Twitter crawler 与sina 微博类似,使用twitter api之前,首先要有twitter的账号,在twitter developer中创建应用(https://apps.twitt ...

  10. IE8上传文件时文件本地路径变成"C:\fakepath\"的问题

    转自:http://yunzhu.iteye.com/blog/1116893 在使用<input id="file_upl" type="file" / ...