jQuery Mobile (中)

前言

昨天我们一起学习了一部分jquery mobile的知识,今天我们继续。

这些是些很基础的东西,有朋友觉得这个没有其它的好,但是学习下不吃亏嘛,我反正也不会一起学习基础啦。

例子请使用手机查看哦

内容区域格式布局

网格布局

jquery mobile提供一种多列布局功能,由于移动设备的屏幕大小原因,一般情况还是不要使用多列布局啦。

jquery mobile提供一种css样式规则来定义多列布局,对应css为ui-block,每列的样式是通过定义前缀+“-a”等方式对网格的列进行布局,a字母根据网格的列数而定。

例如两列布局CSS为:ui-block-a与ui-block-b

两列网格布局

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <div class="ui-grid-a">
15 <div class="ui-block-a">
16 <input type="button" value="确定" />
17 </div>
18 <div class="ui-block-b">
19 <input type="button" value="取消" />
20 </div>
21 </div>
22 </body>
23 </html>

http://sandbox.runjs.cn/show/tdwazgd4

我们看见了他这些都是使用float布局的。

两列布局,需要指定外层div样式是ui-grid-a,ui-grid-a样式用于指定行列采用两列布局样式。

以上两个按钮各占屏幕的50%,采用data-line属性对按钮进行水平排列,按钮宽度根据实际文本而定。

ui-grid-a 两列
ui-grid-b 三列
ui-grid-c 四列
ui-grid-d 五列

我们来看一个三列网格布局:

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <div class="ui-grid-b">
15 <div class="ui-block-a">
16 <input type="button" value="确定" />
17 </div>
18 <div class="ui-block-b">
19 <input type="button" value="取消" />
20 </div>
21 <div class="ui-block-c">
22 <input type="button" value="取消" />
23 </div>
24 </div>
25 </body>
26 </html>

http://sandbox.runjs.cn/show/wxkkjlfy

折叠功能

折叠块是移动端经常用到的效果,只要使用jquery mobile约定的编码规则并且利用HTML5的dataset特性,程序就能生成折叠快了。

其中data-role设置为collapsible,便可以创建一个可折叠的内容区,来个例子吧:

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <div data-role="collapsible">
15 <h3>可折叠区域</h3>
16 <p>刀狂剑痴叶小钗刀狂剑痴叶小钗刀狂剑痴叶小钗刀狂剑痴叶小钗刀狂剑痴叶小钗刀狂剑痴叶小钗</p>
17 </div>
18 </body>
19 </html>

http://sandbox.runjs.cn/show/omulbkhg

form表单

我们手机上的form表单其实都很漂亮了,但是我们的jquery mobile还是给他渲染了下下,是非常不错的。

我们来一个例子看看:

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <label for="name">
15 姓名</label>
16 <input type="text" name="name" id="name" />
17 <label for="password">
18 密码</label>
19 <input type="password" name="password" id="password" />
20 <label for="content">
21 密码</label>
22 <textarea name="content" id="content"></textarea>
23 <label for="number">
24 年龄</label>
25 <input type="number" name="number" id="number" />
26 <label for="tel">
27 手机</label>
28 <input type="tel" name="tel" id="tel" />
29 <label for="tel">
30 email</label>
31 <input type="email" name="email" id="email" />
32 <label for="tel">
33 url</label>
34 <input type="url" name="url" id="url" />
35 <label for="search">
36 搜索</label>
37 <input type="search" name="search" id="search" />
38 </body>
39 </html>

http://sandbox.runjs.cn/show/by9mvtu8

我这里喷一下《HTML5移动Web开发指南》这本书!
唐骏开写的,这家伙写的这本书不行,书中很多例子有问题。

Toggle类型

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <div data-role="fieldcontain">
15 <label for="slider">
16 打开开关:</label>
17 <select name="slider" id="slider" data-role="slider">
18 <option value="off">关闭</option>
19 <option value="on">开启</option>
20 </select>
21 </div>
22 </body>
23 </html>

http://sandbox.runjs.cn/show/ty7aywwm

单选按钮类型

我们要创建一组单选按钮需要这样做:

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <fieldset data-role="controlgroup">
15 <legend>请选择你的年龄范围:</legend>
16 <input type="radio" name="radio1" id="radio1" value="any" checked="checked" />
17 <label for="radio1">
18 不限</label>
19 <input type="radio" name="radio1" id="radio2" value="16-22" />
20 <label for="radio2">
21 16-22岁</label>
22 <input type="radio" name="radio1" id="radio3" value="23-30" />
23 <label for="radio3">
24 23-30岁</label>
25 <input type="radio" name="radio1" id="radio4" value="31-40" />
26 <label for="radio4">
27 31-40岁</label>
28 <input type="radio" name="radio1" id="radio5" value="40" />
29 <label for="radio5">
30 40岁以上</label>
31 </fieldset>
32 </body>
33 </html>

http://sandbox.runjs.cn/show/nwfuhvep

我们看到,他还是挺好看的哈。。。

我们先是竖排,我们设置一个横排的单选按钮看看:

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <fieldset data-role="controlgroup" data-type="horizontal">
15 <legend>请选择你的年龄范围:</legend>
16 <input type="radio" name="radio1" id="radio1" value="any" checked="checked" />
17 <label for="radio1">
18 不限</label>
19 <input type="radio" name="radio1" id="radio2" value="16-22" />
20 <label for="radio2">
21 16-22岁</label>
22 <input type="radio" name="radio1" id="radio3" value="23-30" />
23 <label for="radio3">
24 23-30岁</label>
25 </fieldset>
26 </body>
27 </html>

http://sandbox.runjs.cn/show/vz3bjotg

复选框

单选完了我们来看看复选框:

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <fieldset data-role="controlgroup" data-type="horizontal">
15 <legend>爱好:</legend>
16 <input type="checkbox" name="radio1" id="radio1" value="any" checked="checked" />
17 <label for="radio1">
18 足球</label>
19 <input type="checkbox" name="radio1" id="radio2" value="16-22" />
20 <label for="radio2">
21 篮球</label>
22 <input type="checkbox" name="radio1" id="radio3" value="23-30" />
23 <label for="radio3">
24 编码(危险)</label>
25 </fieldset>
26 </body>
27 </html>

http://sandbox.runjs.cn/show/1zpxdut8

下拉菜单

 1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <link id="jquerymobile_120" rel="stylesheet" type="text/css" class="library"
7 href="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.css">
8 <script id="jquery_182" type="text/javascript" class="library"
9 src="/js/sandbox/jquery/jquery-1.8.2.min.js"></script>
10 <script id="jquerymobile_120" type="text/javascript" class="library"
11 src="/js/sandbox/jquery-mobile/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
12 </head>
13 <body>
14 <div data-role="controlgroup">
15 <label class="select">
16 请选择兴趣
17 <select>
18 <option>电影</option>
19 <option>体育</option>
20 <option>旅游</option>
21 </select>
22 </label>
23
24 <label class="select">
25 请选择兴趣(多选)
26 <select>
27 <optgroup label="一般类">
28 <option>电影</option>
29 <option>体育</option>
30 <option>旅游</option>
31 </optgroup>
32 <optgroup label="特殊类">
33 <option>C</option>
34 <option>C++</option>
35 <option>Java</option>
36 </optgroup>
37 </select>
38 </label>
39 </div>
40 </body>
41 </html>

http://sandbox.runjs.cn/show/zu0zsl2w

我们这里做一点改变,样式会发生变化:

 

http://sandbox.runjs.cn/show/ynvpsuyw

结语

今天篇幅够长了,我们下一篇再继续吧。

 
 
分类: 移动开发

jQuery Mobile (中)的更多相关文章

  1. JQuery mobile中按钮自定义属性的改变

    1..ui-mobile-viewport是jquery mobile默认给body加的class,这样的话包含选择符优先级高一点 <style> .ui-mobile-viewport ...

  2. jQuery Mobile 中创建按钮

    在 jQuery Mobile 中创建按钮 jQuery Mobile 中的按钮可通过三种方法创建: 使用 <button> 元素 使用 <input> 元素 使用 data- ...

  3. jQuery Mobile中的页面加载与跳转机制

    第一次做用jQuery Mobile做东西,发现一些跟平时的思维习惯不太一样的.其中这个框架的页面加载机制便是其中一个.如果不明白其中的奥秘,往往会出现一些让人摸不着头脑的怪现象,比如页面进入后点击按 ...

  4. jQuery Mobile中jQuery.mobile.changePage方法使用详解

    jQuery.mobile.changePage方法用的还是很多的.作为一个老手,有必要对jQuery mobile中实用方法做一些总结.系列文章请看jQuery Mobile专栏.jquery.mo ...

  5. 在 JQuery Mobile 中实现瀑布流图库布局

    先来看在Windows系统的1080P显示器中显示的效果: 这个整合方式几乎没有现存的实例,是自己总结出来的方法,在此记录下来. 首先访问Masonry官网下载masonry.pkgd.min.js: ...

  6. 【初探移动前端开发04】jQuery Mobile (中)

    前言 昨天我们一起学习了一部分jquery mobile的知识,今天我们继续. 这些是些很基础的东西,有朋友觉得这个没有其它的好,但是学习下不吃亏嘛,我反正也不会一起学习基础啦. 例子请使用手机查看哦 ...

  7. jquery.mobile 中 collapsible-set collapsible listview 共同布局问题

    最近项目用上了jquery.mobile这货,在手机上做点简单的显示.之前只知道有这个框架,没把玩过. 特别是事件绑定方面,相比桌面系统下浏览器用着各种不爽,不得要领. 如下图,在做后台系统时,一般左 ...

  8. jQuery Mobile中$.mobile.buttonMarkup方法使用具体解释

    近期在群里遇到多数网友提到$.mobile.buttonMarkup()方法的使用. 我这里就列了一下api的使用说明,以后大家看博客就能解决这个问题.如有不对的地方,请留言指出! jQuery Mo ...

  9. [转]jquery mobile中redirect重定向问题

    本文转自:http://www.cnblogs.com/freeliver54/p/3529813.html 在jquerymobile提交后如果要进行网页重定向时,一定要在form或<a> ...

随机推荐

  1. nodeJS起步 1

    nodeJS起步 -- (1) 先来简单介绍nodeJS 我们知道JavaScript是运行在浏览器中的,浏览器为它提供了一个上下文(context),从而让JavaScript得以解析执行. nod ...

  2. PHP 3:从Login界面谈PHP标记

    原文:PHP 3:从Login界面谈PHP标记 前一篇文章简要介绍了此实例.OK,我们就从第一个页面Login页面入手吧.还是看看界面怎么样,是不是很想指导它到底是如何实现的呢?好的,看看其代码吧: ...

  3. SQL点滴15—在SQL Server 2008中调用C#程序

    原文:SQL点滴15-在SQL Server 2008中调用C#程序 T-SQL的在执行普通的查询的时候是很高效的,但是在执行循环,判断这样的语句的时候效率就不那么的高了.这时可以借助CLR了,我们可 ...

  4. 快速构建Windows 8风格应用26-本地应用数据

    原文:快速构建Windows 8风格应用26-本地应用数据 本篇博文主要介绍如何获取应用的设置和文件容器.如何将数据写入设置.如何从设置中获取数据.如何删除设置中数据.如何将数据写入文件.如何从文件中 ...

  5. CSS3 实现六边形Div图片展示效果

    原文:CSS3 实现六边形Div图片展示效果 效果图: 实现原理: 这个效果的主要css样式有: 1.>transform: rotate(120deg); 图片旋转 2.>overflo ...

  6. Asp.net Identity 系列之 怎样修改Microsoft.AspNet.Identity.EntityFramework.IdentityUser 的 Id 字段的数据类型

    这篇博客我们来学习如何将AspNetUsers 表的Id 字段 的类型由nvarchar(128) 改为Int 并且子增长 1.为什么要修改 如果你运行过 Asp.net mvc 示例项目,你好会发现 ...

  7. 为mongodb加上权限

    我们知道mysql在安装的时候需要我们设置一个数据库默认的用户名和密码,mongodb也不例外,不过mongodb是默认的没有设置访问限制的,不需要输入用户名和密码都可以访问的,但是这样会十分的不安全 ...

  8. 脚手架快速搭建springMVC框架项目

    apid-framework脚手架快速搭建springMVC框架项目   rapid-framework介绍:   一个类似ruby on rails的java web快速开发脚手架,本着不重复发明轮 ...

  9. CRM2011 concurrency问题及解决方案

    CRM2011对删除和添加操作会自动做判断,比如A打开纪录x,B也打开纪录x,然后B删除了纪录x,A去更新的话就会有提示.更新的话是后者覆盖前者,比如A打开纪录x,B打开纪录x,然后B把记录x中的字段 ...

  10. Toad for Oracle的安装

    分享一下Oracle 10gToad for Oracle的安装步骤   三年前用过Oracle,单纯的“用过”,主要就是说对数据库的一些操作,还不包含创建一些存储过程之类的,所以对Oracle仅仅只 ...