生活随笔
收集整理的這篇文章主要介紹了
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 ?引用:
[html] ?view plaincopy
<!DOCTYPE?html>?? <html>?? ????<head>?? ????????<title>Ajax測試</title>?? ????????<meta?charset="gbk">?? ????????<meta?name="viewport"?content="width=device-width,?initial-scale=1">?? ???????? ????????<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函數:
[javascript] ?view plaincopy
<script>?? function?showLoader()?{?? ???? ????$.mobile.loading('show',?{?? ????????text:?'加載中...',? ????????textVisible:?true,? ????????theme:?'a',???????? ????????textonly:?false,??? ????????html:?""??????????? ????});?? }?? ?? function?hideLoader()?? {?? ???? ????$.mobile.loading('hide');?? }?? </script>?? 準備兩個按鈕,一個用于啟動(顯示)加載器,一個用于停止(隱藏)加載器:
[html] ?view plaincopy
<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加載器"?οnclick="showLoader()"/>?? ????????????<input?type="button"?value="隱藏ajax加載器"?οnclick="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顯示加載器的代碼如下:
[javascript] ?view plaincopy
<script>?? ???? ????function?showLoader()?{?? ???????? ????????$.mobile.loadingMessage?=?'加載中...';????? ????????$.mobile.loadingMessageTextVisible?=?true;? ????????$.mobile.loadingMessageTheme?=?'a';???????? ????????$.mobile.showPageLoadingMsg();????????????? ????}?? ?? ???? ????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這兩個方法顯示加載器了。
轉載于:https://www.cnblogs.com/ranzige/p/3853947.html
總結
以上是生活随笔 為你收集整理的jQuery Mobile 手动显示ajax加载器,提示加载中... 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。