PhoneGap API帮助文档翻译Notification提醒

PhoneGap API帮助文档翻译Notification提醒是本文要介绍的内容,主要是来了解PhoneGap API文档的内容,具体PhoneGap API文档内容的详解来看本文,设备的视觉、听觉和触觉通知。

方法:

  1. notification.alert  
  2. notification.confirm  
  3. notification.beep  
  4. notification.vibrate  
  5. notification.alert  

显示一个定制的警告或对话框。

  1. navigator.notification.alert(message, alertCallback, [title], [buttonName]);    
  2. navigator.notification.alert(message, alertCallback, [title], [buttonName]); 

message:对话框信息。(字符串类型)

alertCallback:当警告对话框被忽略时调用的回调函数。(函数类型)

title:对话框标题。(字符串类型)(可选项,默认值为“Alert”)

buttonName:按钮名称(字符串类型)(可选项,默认值为“OK”)

说明:

大多数PhoneGap使用本地对话框实现该功能。然而,一些平台只是简单的使用浏览器的alert函数,而这种方法通常是不能定制的。

支持的平台:

Android

BlackBerry (OS 4.6)

BlackBerry WebWorks (OS 5.0或更高版本)

iPhone

简单的范例:

  1. // Android / BlackBerry WebWorks (OS 5.0 and higher) // iPhone    
  2. function alertDismissed() {    
  3.     // 进行处理    
  4. }    
  5.     
  6. navigator.notification.alert(    
  7.     'You are the winner!',  // 显示信息    
  8.     alertDismissed,         // 警告被忽视的回调函数    
  9.     'Game Over',            // 标题    
  10.     'Done'                  // 按钮名称    
  11. );    
  12.     
  13. // BlackBerry (OS 4.6) // webOS    
  14. navigator.notification.alert('You are the winner!');    
  15. // Android / BlackBerry WebWorks (OS 5.0 and higher) // iPhone  
  16. function alertDismissed() {  
  17.  // 进行处理  
  18. }  
  19.  
  20. navigator.notification.alert(  
  21.  'You are the winner!',  // 显示信息  
  22.     alertDismissed,         // 警告被忽视的回调函数  
  23.     'Game Over',            // 标题  
  24.     'Done'                  // 按钮名称  
  25. );  
  26.  
  27. // BlackBerry (OS 4.6) // webOS  
  28. navigator.notification.alert('You are the winner!');  
  29. 完整的范例:  
  30. view plaincopy to clipboardprint?>    
  31. <html>    
  32. <head>        
  33. <title>Notification Exampletitle>    
  34.     
  35. <script type="text/javascript" charset="utf-8" src="phonegap.js">script>    
  36. <script type="text/javascript" charset="utf-8">    
  37.     
  38.     // 等待加载PhoneGap    
  39.     document.addEventListener("deviceready", onDeviceReady, false);     
  40.         
  41.     // PhoneGap加载完毕    
  42.     function onDeviceReady() {    
  43.         // 空    
  44.     }    
  45.         
  46.     // 警告对话框被忽视    
  47.     function alertDismissed() {    
  48.         // 进行处理    
  49.     }    
  50.         
  51.     // 显示一个定制的警告框    
  52.     function showAlert() {    
  53.         navigator.notification.alert(    
  54.             'You are the winner!',  // 显示信息    
  55.             alertDismissed,         // 警告被忽视的回调函数    
  56.             'Game Over',            // 标题    
  57.             'Done'                  // 按钮名称    
  58.         );    
  59.     }    
  60.     
  61. script>    
  62. head>    
  63. <body>    
  64.     <p><a href="#" onclick="showConfirm(); return false;">Show Confirma>p>    
  65. body>    
  66. html>    
  67. > 
  68. <html> 
  69. <head>   
  70. <title>Notification Exampletitle> 
  71.  
  72. <script type="text/javascript" charset="utf-8" src="phonegap.js">script> 
  73. <script type="text/javascript" charset="utf-8"> 
  74.  
  75.  // 等待加载PhoneGap  
  76.  document.addEventListener("deviceready", onDeviceReady, false);   
  77.    
  78.  // PhoneGap加载完毕  
  79.  function onDeviceReady() {  
  80.   // 空  
  81.  }  
  82.    
  83.  // 警告对话框被忽视  
  84.  function alertDismissed() {  
  85.   // 进行处理  
  86.  }  
  87.    
  88.  // 显示一个定制的警告框  
  89.  function showAlert() {  
  90.   navigator.notification.alert(  
  91.    'You are the winner!',  // 显示信息  
  92.    alertDismissed,         // 警告被忽视的回调函数  
  93.    'Game Over',            // 标题  
  94.    'Done'                  // 按钮名称  
  95.   );  
  96.  }  
  97.  
  98. script> 
  99. head> 
  100. <body> 
  101.  <p><a href="#" onclick="showConfirm(); return false;">Show Confirma>p> 
  102. body> 
  103. html> 
  104. notification.confirm   

显示一个可定制的确认对话框。

  1. navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels]);    
  2. navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels]); 

message:对话框信息。(字符串类型)

confirmCallback:按下按钮后触发的回调函数,返回按下按钮的索引(1、2或3)。(函数类型)

title:对话框标题。(字符串类型)(可选项,默认值为“Confirm”)

buttonLabels:逗号分隔的按钮标签字符串。(字符串类型)(可选项,默认值为“OK、Cancel”)

posted @ 2013-03-04 16:11  残星  阅读(420)  评论(0编辑  收藏  举报