2012年11月2日星期五

phonegap-event

监听各类事件,我用的是phonegap2.0.0的版本,越高级的版本支持功能就越多。 

  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>Event Example</title>  
  5.   
  6.     <script type="text/javascript" charset="utf-8" src="jquery-1.8.1.min.js"></script>  
  7.     <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>  
  8.     <script type="text/javascript" charset="utf-8">  
  9.   
  10.       
  11.     // Wait for Cordova to load  
  12.     // details plz see http://docs.phonegap.com/en/2.0.0/cordova_events_events.md.html#Events  
  13.     document.addEventListener("deviceready", onDeviceReadyEvent, false);  
  14.     document.addEventListener("pasue", onPasueEvent, false);  
  15.     document.addEventListener("resume", onResumeEvent, false);  
  16.     document.addEventListener("online", onlineEvent, false);  
  17.     document.addEventListener("offline", offlineEvent, false);  
  18.     document.addEventListener("backbutton", onBackbuttonEvent, false);  
  19.     document.addEventListener("batterycritical", onBatterycriticalEvent, false);  
  20.     document.addEventListener("batterylow", onBatterylowEvent, false);  
  21.     document.addEventListener("batterystatus", onBatterystatusEvent, false);  
  22.     document.addEventListener("menubutton", onMenubuttonEvent, false);  
  23.     document.addEventListener("startcallbutton", onStartcallbuttonEvent, false);  
  24.     document.addEventListener("volumedownbutton", onVolumedownbuttonEvent, false);  
  25.     document.addEventListener("volumeupbutton", onVolumeupbuttonEvent, false);  
  26.   
  27.   
  28.     // Cordova is ready  
  29.     //  
  30.     function onDeviceReadyEvent() {  
  31.         $("#msg").append("==>onDeviceReadyEvent<p/>");  
  32.     }  
  33.       
  34.     function onPasueEvent() {  
  35.         $("#msg").append("==>onPasueEvent<p/>");  
  36.     }  
  37.       
  38.     function onResumeEvent() {  
  39.         $("#msg").append("==>onResumeEvent<p/>");  
  40.     }  
  41.       
  42.     function onlineEvent() {  
  43.         $("#msg").append("==>onlineEvent<p/>");  
  44.     }  
  45.       
  46.     function offlineEvent() {  
  47.         $("#msg").append("==>offlineEvent<p/>");  
  48.     }  
  49.       
  50.     function onBackbuttonEvent() {  
  51.         $("#msg").append("==>onBackbuttonEvent<p/>");  
  52.     }  
  53.       
  54.     function onBatterycriticalEvent() {  
  55.         $("#msg").append("==>onBatterycriticalEvent<p/>");  
  56.     }  
  57.       
  58.     function onBatterylowEvent() {  
  59.         $("#msg").append("==>onBatterylowEvent<p/>");  
  60.     }  
  61.       
  62.     function onBatterystatusEvent() {  
  63.         $("#msg").append("==>onBatterystatusEvent<p/>");  
  64.     }  
  65.       
  66.     function onMenubuttonEvent() {  
  67.         $("#msg").append("==>onMenubuttonEvent<p/>");  
  68.     }  
  69.       
  70.     function onStartcallbuttonEvent() {  
  71.         $("#msg").append("==>onStartcallbuttonEvent<p/>");  
  72.     }  
  73.       
  74.     function onVolumedownbuttonEvent() {  
  75.         $("#msg").append("==>onVolumedownbuttonEvent<p/>");  
  76.     }  
  77.       
  78.     function onVolumeupbuttonEvent() {  
  79.         $("#msg").append("==>onVolumeupbuttonEvent<p/>");  
  80.     }  
  81.   
  82.     </script>  
  83.   </head>  
  84.   <body>  
  85.     <h1>Event Example</h1>  
  86.     <div id="msg"></div>  
  87.   </body>  
  88. </html>  

没有评论:

发表评论