標籤: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種初始化事件。