小強的HTML5移動開發之路(50)——jquerymobile頁面初始化過程

來源:互聯網
上載者:User

標籤:android   jquery mobile   初始化過程   事件   html5   

為了方便說明和更加直觀的展示jquerymobile的頁面初始化過程以及各個事件的觸發過程,我繪製了一幅流程圖:


圖中用紅色框圈起來的是介面中的事件,測試代碼如下:

<!DOCTYPE html><html><head><title>練習</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,       initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" /><link href="css/jquery.mobile-1.0.1.min.css"       rel="stylesheet" type="text/css"/><script src="js/jquery-1.6.4.js"       type="text/javascript" ></script><script src="js/jquery.mobile-1.0.1.js"        type="text/javascript" ></script><script>$(document).ready(function(e){alert("document.ready被觸發");});$(document).live("mobileinit", function(){alert("mobileinit事件觸發");});$(document).delegate("#page_MobileInit0", "pageinit", function(){alert("page_MobileInit0頁面的pageinit事件被觸發");});$(document).delegate("#page_MobileInit0", "pageshow", function(){alert("page_MobileInit0頁面的pageshow事件被觸發");});$(document).delegate("#page_MobileInit1", "pageinit", function(){alert("page_MobileInit1頁面的pageinit事件被觸發");});$(document).delegate("#page_MobileInit1", "pageshow", function(){alert("page_MobileInit1頁面的pageshow事件被觸發");});</script>    </head><body><section id="page_MobileInit0" data-role="page"><header data-role="header"><h1>頁面事件</h1></header><div class="content" data-role="content"><p>jQuery Mobile頁面初始化是通過mobileinit、$(document).ready()以及pageinit實現的</p><a href="#" onclick="$(document).trigger(‘mobileinit‘)">手動觸發mobileinit事件</a><a href="#page_MobileInit1">下一頁</a><br/></p></div></section><section id="page_MobileInit1" data-role="page"><header data-role="header"><h1>頁面事件</h1></header><div class="content" data-role="content"><p>jQuery Mobile頁面初始化是通過pageinit實現的<br/><a href="#page_MobileInit0">返回</a></p></div></section></body></html>
除了上面介紹的事件外,還有onload事件。當所有相關內容(包括圖片)載入完成後會觸發onload事件。因為受到圖片等內容的影響,onload事件的觸發時間比較晚。雖然在頁面開發中也會用到onload事件,但是在jQuery Mobile開發中,主要使用的是mobileinit、ready()和pageinit這3種初始化事件。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.