deviceready事(shì)件(jiàn)(≈" 使用(yòng)PhoneGap開(kāi)發時(shí)α∑φγ,deviceready事(shì)件(jiàn)✘εφ是(shì)常用(yòng)的(de),devicere♠∏₹ady事(shì)件(jiàn)在設備的(de)本地(dì₩β★)環境和(hé)頁
面加載完成後才觸發,一(yī)般晚于jquery的(de)ready事(sh↕γ©®ì)件(jiàn))
pause事(shì)件(jiàn)(PhoneGap $應用(yòng)被置為(wèi)後台時(shí)觸發)→γ®®
resume事(shì)件(jiàn)(PhoneGa↑εp從(cóng)後台置為(wèi)前台時(shí)觸發)
online事(shì)件(jiàn) (應用(yòΩng)連接網絡時(shí)觸發)
offline事(shì)件(jiàn)(應用(yòng)斷開(kāi)網♦↔÷∏絡時(shí)觸發)
backbutton事(shì)件(jiàn)(單機(jī)返回按鈕時(¶&¶✔shí)觸發)
menubutton事(shì)件(jiàn)(單機(jī)↓®>§菜單按鈕時(shí)觸發)
batterycritical事(shì)件(jiàn)(Pho₩<±neGap應用(yòng)檢測到(dào)電(di±∑àn)池電(diàn)量到(dào)達20%警告時(shσ₹✔÷í)觸發 包括兩個(gè)屬性:levelφλα:電(diàn)池剩餘電(diàn)量
的(de)百分(fēn)比,取值範圍0-1© ±™00;isPlugged:boolean型的(d↔¶π™e)值,表示設備是(shì)否接通(tōng)電(diàn)源。)
batterylow事(shì)件(jiàn)(∏↑>電(diàn)量非常低(dī)5%的(de)情況下(£®xià)觸發 包括兩個(gè)屬性:level:電(diàn)池剩餘¥≈電(diàn)量的(de)百分(fēn)比,取值範圍0-100;→™
isPlugged:boolean型的(de)值,×™表示設備是(shì)否接通(tōng)電(diàn)源。)
batterystatus事(shì)件(jiàn)(φ♦監控電(diàn)池每當電(diàn)量變化(↔✘'huà)1%時(shí)觸發一(yī)次 包括兩個(gè)屬性:le↑☆≈vel:電(diàn)池剩餘電(diàn)量的(de)百分(fēn)比,取≠→×♣值
範圍0-100;isPlugged:boolean型的(de)值,表示設備是(♠≈•§shì)否接通(tōng)電(diàn)源。)
示例
<html>
<head>
<script type="text/javasc§πript">
 α ; $(document).ready(function(↑✘){
&nbs÷p; &nb↔→•€sp; document.ad↓←dEventListener("devicerea₹≈<dy", myDeviceReadyListener, falseε 'ε);
}δδ★ );
funct&ion myDeviceReadyListener(){φ♥<♣
&nb♥≈↕ sp; console.log("設備加∞←載完畢!");
&n☆ ↕bsp; ☆✔± $("#deviceStatus<§∑≈ .ui-btn-text").α•♣♣text("設備加載完畢!");
&λσnbsp; //✘↔¥注冊其他(tā)事(shì)件(jiàn)
&nb↓©©sp; ¥"¶document.addEventListener(&quo<♠£t;pause", myPauseλ™φ±Listener, false);
&n↔☆★bsp; &nbs£♦δ'p; document.addEventLis↑☆₽♥tener("resume"φ★π, myResumeListener, false φ÷≥);
&nb≈•'sp; &n₽¶bsp; document.addEventListener("≈↕¶ε;online", myOnlineListen♦β er, false);
&n∏© bsp; documentα"§€.addEventListener("offli ∑<✔ne", myOfflineList♦π₹→ener, false);
≈₩ docume€←→nt.addEventListener(♦ λ"backbutton", myBacε←•kbuttonListener, false)∞✘;
&nbs£&p; &nbs✘←πp; document.addEventListener(&quo ₩t;menubutton", myMenubuttonListene→←∞±r, false);
&n≤¥bsp; window.addEvent¶<Listener("batterystatu₹∑β s", myBatterystatusListener, false©);
&n↑♦bsp; window.∑ addEventListener("↓♠batterylow", myBatter ←€ylowListener, false);
&nbΩ®Ω sp; window.addEventγ≠Listener("batteryc←€ritical", myBatterycritic®ε$alListener, false);
}
 σ♣; function myBatterystatusListener&" ≠(info){
&n→ bsp; c₽™onsole.log(" 電(diàn)量值&qu'&•ot; + info.level);
&n★÷bsp; &nb"≠sp; $("#batterystatus .ui-btn-t§™ext").text(" 電(diàn ≥♦∏)量值" + info.level);
&n$¶✘≥bsp; }
function myBaδ♥tterylowListener(info){
 ₽∑; co<£≠nsole.log(" 電(dià '®n)量低(dī),請(qǐng)及時(shí)充電(diàn),電(diàn✘)量值" + info.leveπ↓←l);
}
&nb₽¥✔βsp; function myBatterycriticalListene¥©r(info){
&←♣nbsp; &n∑∑♣☆bsp; console.log(" 電(diàn♣↓✘)量過低(dī),請(qǐng)及時(shí)充電(diàn),電(dià₩♦₩σn)量值" + info.level);
&nbs®✘<p; }
&nbs♦γ&p; function myPauseListener(){
&nb™sp; '<¶σconsole.log("應用(yòng)被置為(w×α♥èi)後台");
&nb¥αφsp; $("#deΩ₩viceCurrentStatus .ui-btn-text").t§≠♠'ext("應用(yòng)為(wèi)後台&q↔↕uot;);
}
&$λnbsp; function myResumeLi&→±stener(){
&n≈¶₹bsp; &nbs§≥ p; console.log("應用(yσ™✔↔òng)被置為(wèi)前台");
 £>; ∞ $("#deviceC÷∑©urrentStatus .ui-btn♥↔-text").text("應用♦ε↕(yòng)為(wèi)前台");≥§€
£•★ }
fu≥'nction myOnlineListener(){→
™∑± &n§σ↔bsp; conso♥✔≤§le.log("網絡連接在線");
&nbsλ p; $(&q₩≤β✘uot;#deviceConectionStatus ¥β¶÷.ui-btn-text").tex♣β§t(" 網絡連接在線");
}
↑♠∏ function myOfflineListener( δ ){
&±β∑nbsp; co↔nsole.log("網絡連接離(lí)線");
&nbs☆♣♣$p; $("∞₽π#deviceConectionStatus ∑φ.ui-btn-text").text(" 網絡連接離(πλlí)線");
}
v"™∞<ar backTouchCount = 0;
var ↕≠ menuTouchCount = 0;
 α♦↑; function myBackbuttonListeα λ÷ner(){
&nbs✔↑→ p; cons•®ole.log("返回按鈕被按了σ₩€(le)");
€♦© &n<•bsp; backTouchCount++♦±♥;
 ¶∏; &nb×→'εsp; $("#backButtonToucφ¶ h .ui-btn-text").♦♥>text("返回按鈕被按"§λ∑;+ backTouchCount +"次&q>≈βuot;);
}
&nbs'p; function myMe∑≈βnubuttonListener(){
 ✔₹✔♠;  ♦÷♠×; console.log("菜₹<γ§單按鈕被按了(le)");
&nbs∏α€p;  ♣&; menuTouchCount++;
&nbsδ±≠p; ↕<$("#menuButtonTouch .ui-btn-t εext").text("菜•σ單按鈕被按"+ menuTouchCount +"δα;次");
&nb←∞★&sp; }
</script>
</head>
<body>
∏♦ <div data-role=&quo✔€t;page">
&n₽Ω∏bsp; <§δ₹div data-role="header"&♦∏gt;
&♠δ"§nbsp; &®&≤→nbsp; <h1πφ♠±>PhoneGap 實戰</h1>
&nbs∏γ♣≤p; <"₩;/div>
&✔$ ♠nbsp; <div ≈ data-role="content"Ω';>
&♠≥nbsp;  →÷•; & ∞γ§lt;a href="#" data-r< →¥ole="button" id="d★¥ eviceStatus">設備×₹✘加載中....</a>
&nbs ™p;  ¶↓≥; <a href="#" d®♥ata-role="button"×¥♣₹ id="deviceCurrentStatus"&¶♣÷€gt;應用(yòng)為(wèi)前台</a>
&nbs±φβp; ©≈ <a href=&q<↓uot;#" data-role="button&qu©↑↔ot; id="deviceConectionS♦≈γtatus">連接加載中....</'"a>
&λ §∞nbsp; &♦™♠✘nbsp; <a h♣€ref="#" data "$π-role="button" id="ba₽®↕∑ckButtonTouch">返®<♠'回按鈕被按0 次</a>
®$₹ &nbs∞∑>p; &nε♠bsp; <a href="#&®σ≈♣quot; data-role="button" id=&≥γ±≥quot;menuButtonTouch&q σΩ☆uot;>菜單按鈕被按0 次</a&g®✔t;
&nb↓↔sp; ♣★ <a href="#&&" data-role="bu™βtton" id="batterystatus&quo✘Ωt;>電(diàn)量獲取中...</a>
&n ✘≤bsp; </div>
&n×♦φbsp; <div dat✘×÷→a-role="footer"> σ↓≠
&nbsφ♦→p; &nb£λ♠≥sp; <h4&'₩gt; </h4>
&nb∞ sp; </div>
</div>∏&☆±;
</body>
</html>