PhoneGap API帮助文档翻译Notification提醒
PhoneGap API帮助文档翻译Notification提醒是本文要介绍的内容,主要是来了解PhoneGap API文档的内容,具体PhoneGap API文档内容的详解来看本文,设备的视觉、听觉和触觉通知。
方法:
- notification.alert
 - notification.confirm
 - notification.beep
 - notification.vibrate
 - notification.alert
 
显示一个定制的警告或对话框。
- navigator.notification.alert(message, alertCallback, [title], [buttonName]);
 - navigator.notification.alert(message, alertCallback, [title], [buttonName]);
 
message:对话框信息。(字符串类型)
alertCallback:当警告对话框被忽略时调用的回调函数。(函数类型)
title:对话框标题。(字符串类型)(可选项,默认值为“Alert”)
buttonName:按钮名称(字符串类型)(可选项,默认值为“OK”)
说明:
大多数PhoneGap使用本地对话框实现该功能。然而,一些平台只是简单的使用浏览器的alert函数,而这种方法通常是不能定制的。
支持的平台:
BlackBerry (OS 4.6)
BlackBerry WebWorks (OS 5.0或更高版本)
简单的范例:
- // Android / BlackBerry WebWorks (OS 5.0 and higher) // iPhone
 - function alertDismissed() {
 - // 进行处理
 - }
 - navigator.notification.alert(
 - 'You are the winner!', // 显示信息
 - alertDismissed, // 警告被忽视的回调函数
 - 'Game Over', // 标题
 - 'Done' // 按钮名称
 - );
 - // BlackBerry (OS 4.6) // webOS
 - navigator.notification.alert('You are the winner!');
 - // Android / BlackBerry WebWorks (OS 5.0 and higher) // iPhone
 - function alertDismissed() {
 - // 进行处理
 - }
 - navigator.notification.alert(
 - 'You are the winner!', // 显示信息
 - alertDismissed, // 警告被忽视的回调函数
 - 'Game Over', // 标题
 - 'Done' // 按钮名称
 - );
 - // BlackBerry (OS 4.6) // webOS
 - navigator.notification.alert('You are the winner!');
 - 完整的范例:
 - view plaincopy to clipboardprint?>
 - <html>
 - <head>
 - <title>Notification Exampletitle>
 - <script type="text/javascript" charset="utf-8" src="phonegap.js">script>
 - <script type="text/javascript" charset="utf-8">
 - // 等待加载PhoneGap
 - document.addEventListener("deviceready", onDeviceReady, false);
 - // PhoneGap加载完毕
 - function onDeviceReady() {
 - // 空
 - }
 - // 警告对话框被忽视
 - function alertDismissed() {
 - // 进行处理
 - }
 - // 显示一个定制的警告框
 - function showAlert() {
 - navigator.notification.alert(
 - 'You are the winner!', // 显示信息
 - alertDismissed, // 警告被忽视的回调函数
 - 'Game Over', // 标题
 - 'Done' // 按钮名称
 - );
 - }
 - script>
 - head>
 - <body>
 - <p><a href="#" onclick="showConfirm(); return false;">Show Confirma>p>
 - body>
 - html>
 - >
 - <html>
 - <head>
 - <title>Notification Exampletitle>
 - <script type="text/javascript" charset="utf-8" src="phonegap.js">script>
 - <script type="text/javascript" charset="utf-8">
 - // 等待加载PhoneGap
 - document.addEventListener("deviceready", onDeviceReady, false);
 - // PhoneGap加载完毕
 - function onDeviceReady() {
 - // 空
 - }
 - // 警告对话框被忽视
 - function alertDismissed() {
 - // 进行处理
 - }
 - // 显示一个定制的警告框
 - function showAlert() {
 - navigator.notification.alert(
 - 'You are the winner!', // 显示信息
 - alertDismissed, // 警告被忽视的回调函数
 - 'Game Over', // 标题
 - 'Done' // 按钮名称
 - );
 - }
 - script>
 - head>
 - <body>
 - <p><a href="#" onclick="showConfirm(); return false;">Show Confirma>p>
 - body>
 - html>
 - notification.confirm
 
显示一个可定制的确认对话框。
- navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels]);
 - navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels]);
 
message:对话框信息。(字符串类型)
confirmCallback:按下按钮后触发的回调函数,返回按下按钮的索引(1、2或3)。(函数类型)
title:对话框标题。(字符串类型)(可选项,默认值为“Confirm”)
buttonLabels:逗号分隔的按钮标签字符串。(字符串类型)(可选项,默认值为“OK、Cancel”)
                    
                
                
            
        
浙公网安备 33010602011771号