jQuery Mobile 手动显示ajax加载器,提示加载中...
在使用jQuery Mobile开发时,有时候我们需要在请求ajax期间,显示加载提示框(例如:一个旋转图片+一个提示:加载中...)。这个时候,我们可以手动显示jQuery Mobile的加载器,大致流程如下:
1. 启动加载器,显示“加载中...”;
2. 进行ajax请求,请求完成后更新页面数据,刷新jQuery Mobile控件样式;
3. 关闭加载器。
下面就来讲解jQuery Mobile 1.2.0 和 1.1.0 中手动显示加载器的方法(很简单,几行代码就OK了!)。
首先是jQuery Mobile 1.2.0 引用:
- <!DOCTYPE html>
- <html>
- <head>
- <title>Ajax测试</title>
- <meta charset="gbk">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!-- 从官方下载的文件放在项目的 jquery-mobile 目录中 -->
- <link rel="stylesheet" href="jquery-mobile/jquery.mobile-1.2.0.min.css"/>
- <link rel="stylesheet" href="jquery-mobile/jquery.mobile.structure-1.2.0.min.css"/>
- <script src="jquery-mobile/jquery-1.8.2.min.js"></script>
- <script src="jquery-mobile/jquery.mobile-1.2.0.min.js"></script>
- <head>
编写javascript函数:
- <script>
- //显示加载器
- function showLoader() {
- //显示加载器.for jQuery Mobile 1.2.0
- $.mobile.loading('show', {
- text: '加载中...', //加载器中显示的文字
- textVisible: true, //是否显示文字
- theme: 'a', //加载器主题样式a-e
- textonly: false, //是否只显示文字
- html: "" //要显示的html内容,如图片等
- });
- }
- //隐藏加载器.for jQuery Mobile 1.2.0
- function hideLoader()
- {
- //隐藏加载器
- $.mobile.loading('hide');
- }
- </script>
准备两个按钮,一个用于启动(显示)加载器,一个用于停止(隐藏)加载器:
- <body>
- <div data-role="page">
- <!-- 头部 -->
- <div data-role="header">
- <h3>Ajax测试</h3>
- </div>
- <!-- 内容 -->
- <div data-role="content">
- <h3>Ajax测试</h3>
- <input type="button" value="显示ajax加载器" onclick="showLoader()"/>
- <input type="button" value="隐藏ajax加载器" onclick="hideLoader()"/>
- </div>
- </body>
效果如下(主题为:'a'):

当然,你可以调整$.mobile.loading('show', { ... }中的参数,实验各种不同的加载器效果。
加载器的具体说明见jQuery Mobile 1.2.0 官方demo演示说明:
http://jquerymobile.com/demos/1.2.0/docs/pages/loader.html
注意:jQuery Mobile1.1.0中显示ajax加载器与1.2.0版本完全不同!坑爹!
jQuery Mobile 1.1.0显示加载器的代码如下:
- <script>
- //显示加载器
- function showLoader() {
- //显示加载器.for jQuery Mobile 1.1.0
- $.mobile.loadingMessage = '加载中...'; //显示的文字
- $.mobile.loadingMessageTextVisible = true; //是否显示文字
- $.mobile.loadingMessageTheme = 'a'; //加载器主题样式a-e
- $.mobile.showPageLoadingMsg(); //显示加载器
- }
- //隐藏加载器.for jQuery Mobile 1.1.0
- function hideLoader() {
- //隐藏加载器
- $.mobile.hidePageLoadingMsg();
- }
- </script>
显示的效果倒是差不多。
官方1.2.0文档中对1.1.0的说明如下:
The page loading dialog was previously configured globally with three settings
$.mobile.loadingMessage,
$.mobile.loadingMessageTextVisible, and
$.mobile.loadingMessageTheme
which are now deprecated. In addition to the methods for showing and hiding,
$.mobile.showPageLoadingMsg and
$.mobile.hidePageLoadingMsg are also deprecated.
意思就是说:在1.2.0版本不在使用$.mobile.showPageLoadingMsg和$.mobile.hidePageLoadingMsg这两个方法显示加载器了。
jQuery Mobile 手动显示ajax加载器,提示加载中...的更多相关文章
- jQuery Mobile 手动显示ajax加载器
在jquery mobile开发中,经常需要调用ajax方法,异步获取数据,如果异步获取数据方法由于网速等等的原因,会有一个反应时间,如果能在点击按钮后数据处理期间,给一个正在加载的提示,客户体验会更 ...
- jquery mobile 和phonegap开发总结之三跨域加载页面
跨域加载 一要进行一定的配置见下面 $( document ).bind( "mobileinit", function() { // Make your jQuery Mobil ...
- 如何让 jQuery Mobile 不显示讨厌的 loading 界面
jQuery Mobile 的一个BUG: 当不采用 ajax 以及 他自己的 back 返回的时候,即: 点击浏览器后退按钮时,将会从缓存之中加载页面,此时,讨厌的 loading 动画出来了,而且 ...
- 使用js加载器动态加载外部Javascript文件
原文:http://www.cnblogs.com/xdp-gacl/p/3927417.html 今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js var ...
- JavaScript学习总结(十九)——使用js加载器动态加载外部Javascript文件
今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js 1 var MiniSite=new Object(); 2 /** 3 * 判断浏览器 4 */ 5 M ...
- 使用js加载器动态加载外部js、css文件
let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.us ...
- jquery mobile 的loading提示“正在加载...”在不同版本中的不同实现方式
在jquery mobile开发中,在页面的切换.或者ajax获取数据时由于网速慢等其他原因,会有一个加载的时间,如果能在这段时间给一个“正在加载...”的提示,用户体验会更好.下面来简单的介绍一下在 ...
- jQuery Mobile 脚本加载问题
刚开始使用jQuery Mobile,发现很多问题需要重新考虑,比如脚本加载问题. 在普通html中,如果a.html中有链接到b.html,b.html中有类似代码: $(document).rea ...
- jQuery Mobile中的页面加载与跳转机制
第一次做用jQuery Mobile做东西,发现一些跟平时的思维习惯不太一样的.其中这个框架的页面加载机制便是其中一个.如果不明白其中的奥秘,往往会出现一些让人摸不着头脑的怪现象,比如页面进入后点击按 ...
随机推荐
- SoapUI中Groovy的实用方法
1.依照上次结果判断下步是否执行: import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus myTestStep ...
- linux(centos7)下安装tomcat7
1.下载tomcat1.7.tar.gz 2.将文件放到/usr/local中 #cp tomcat1.7.tar.gz /usr/local 3.进入到/usr/local中,解压缩tomcat1. ...
- servicestack操作redis
tatic void Main(string[] args) { );//redis服务IP和端口 #region =insert= var storeMembers = new List<st ...
- Use weakref module in a cache or mapping
The weakref module allows the Python programmer to create weak references to objects. In the followi ...
- 我的新计划 《2Dof Racing Simulator》2014/3/9 20:30:00
最近好久都没来网站上了,也没心思和时间去弄VellLock和升级V&View了.一直在蕴量这做一件大玩意. 最近一直都很忙,忙着做数电课设,还有各种实验,可是我的心思不在这些东西上,当然除了数 ...
- CircleLayout
CircleLayout https://developer.apple.com/library/ios/samplecode/CircleLayout/Introduction/Intro.html ...
- cocos2dx实现功能强大的RichText控件
转自:http://blog.csdn.net/ljxfblog/article/details/26136773 最近准备做一个聊天系统,开始准备使用cocos2dx的UIRichText控件来显示 ...
- 判定元素正在插入到DOM树——DOMNodeInsertedIntoDocument
在firefox, webkit中我们可以使用DOMNodeInsertedIntoDocument事件,但这个事件很快变废弃了,虽然浏览器还是很有节操地支持它们,但哪一天不在也很难说.比如说fire ...
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...
- UVALive 5881 Unique Encryption Keys (DP)
Unique Encryption Keys 题目链接: http://acm.hust.edu.cn/vjudge/problem/26633 Description http://7xjob4.c ...