【jQueryMobile】Helloworld與頁面切換

來源:互聯網
上載者:User

標籤:jquery mobile   helloworld   移動平台   手機   介面   

jQuery Mobile是jQuery 在手機上和平板裝置上的版本。jQuery Mobile 不僅會給主流移動平台帶來jQuery核心庫,而且會發布一個完整統一的jQuery移動UI架構。支援全球主流的移動平台。就是能夠迅速能把頁面寫成APP的介面,讓使用者瀏覽網頁,相當於在使用布局好的app一樣。

首先要在jQueryMobile(點擊開啟連結)下載一個壓縮包,然後把這個壓縮包的所有內容拉到你的網站資料夾,雖然在網頁僅僅是引用jquery.mobile-1.4.5.js與jquery.mobile-1.4.5.css,但是其他的輔助檔案除了說明文檔demo檔案夾外缺一不可。即使它的js檔案與css檔案,但它不像Bootstrap一樣,把所有功能整合到一個js裡面,如果缺乏某些檔案夾,某些表徵圖可能無法顯示。而且,請把原根資料夾jquery.mobile-1.4.5的名字改成jqmobile或者其他,反本文件夾中別有.-這些標點符號,否則,在網頁中引用jquery.mobile-1.4.5.js與jquery.mobile-1.4.5.css可能失效。

同時,jquery.mobile作為一個外掛程式,需要jQuery1.11(點擊開啟連結)支援,可以到jQuery官網中下載相容舊瀏覽器IE6的jQuery1.11(點擊開啟連結),而不是不相容舊瀏覽器IE6的jQuery2。把下載到的jQuery1.11.js也與jQueryMobile的檔案放在一起吧。如:


之後就可以在網頁編寫頁面,代碼如下,詳情請看注釋。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>a</title><!--要求自動適應螢幕,不允許手機使用者自由調整頁面尺寸--><meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"><link rel="stylesheet" href="jqmobile/jquery.mobile-1.4.5.css"><script src="jqmobile/jquery-1.11.1.js"></script><script src="jqmobile/jquery.mobile-1.4.5.js"></script></head><body><!--定義一個page容器,所有組件都必須寫在裡面,要求其填充到整個螢幕--><div data-role="page" data-position="fixed" data-fullscreen="true"><!--這就是標題列,在最新的jqmobile中,內建的主題只刪得只剩黑白兩色,data-theme="a"為白,data-theme="b"為黑--><!--data-tap-toggle = "false"是禁止使用者點擊頁面內容,也就是content就隱藏頁尾-->  <div data-role="header" data-theme="b" data-tap-toggle = "false">    <h1>Title</h1>  </div>  <div data-role="content">    <p>中文是沒有問題的aaa</p>     </div>  <div data-role="footer" data-position="fixed" data-fullscreen="true"  data-theme="b" data-tap-toggle = "false">      <div data-role="navbar">      <ul>      <!--讓a按鈕處於凹陷狀態,使用info表徵圖,在按鈕中跳轉到其它頁面,要使用target="_self",否則連結出錯-->        <li><a href="#" class="ui-btn-active ui-state-persist" data-icon="info">a</a></li>        <li><a href="b.html" target="_self" data-icon="grid">b</a></li>        <li><a href="c.html" target="_self" data-icon="star">c</a></li>      </ul>    </div>      </div> </div> </body></html>

於是,就可以寫出如下的網頁:


其中w3cschool上對於主題的論述有些過時,請注意,最新版本的jQueryMobile的內建主題刪得只剩下兩種。jQueryMobile的內建表徵圖如下:


在調試的使用,應該使用Google瀏覽器、Firefox瀏覽器等進階瀏覽器,因為WIN7內建的IE8出現很多相容性的問題,畢竟這貨就是用來寫手機頁面的,因此別妄想把jQueryMobile運用到電腦頁面上去……

【jQueryMobile】Helloworld與頁面切換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.