gzgchzc博客最新更新地址:http://blog.gzvtc.cc/
Dialogs
顯示一個系統提示對話框
cordova plugin add cordova-plugin-dialogs
方法(Methods)
alert(message, title, buttonName)
顯示一個普通對話框
參數 類型 說明
message String 對話框提示的一段文字
title String 對話框標題 默認:alert
buttonName String 對話框按鈕名稱 默認:ok
confirm(message, title, buttonArray)
顯示一個帶有指定消息和取消及取消按鈕的對話框(可以自定義兩個按鈕的名稱)
參數 類型 說明
message String 對話框提示的一段文字
title String 對話框標題 默認:alert
buttonArray Array 按鈕名名稱 是一個數組 默認:[‘ok’,’Cancel’]
返回值 Integer 1或2取決於你點擊了哪一個按鈕
prompt(message, title, buttonArray, defaultText)
顯示可提示用戶進行輸入的對話框
參數 類型 說明
message String 對話框提示的一段文字
title String 對話框標題 默認:alert
buttonArray Array 按鈕名名稱 是一個數組 如:[‘ok’,’Cancel’]
defaultText String 用戶輸入提示信息
返回值 Object 用於接受用戶輸入:result.input1 判斷用戶點擊那哪一個按鈕 返回一個索引:result.buttonIndex
beep(repetitions)
顯示可提示用戶進行輸入的對話框
參數 類型 說明
repetitions Integer 設置彈出對話框延遲以秒爲單位
Examples
module.controller('MyCtrl', function($scope, $cordovaDialogs) {
$cordovaDialogs.alert('message', 'title', 'button name')
.then(function() {
// callback success
});
$cordovaDialogs.confirm('message', 'title', ['button 1','button 2'])
.then(function(buttonIndex) {
// no button = 0, 'OK' = 1, 'Cancel' = 2
var btnIndex = buttonIndex;
});
$cordovaDialogs.prompt('msg', 'title', ['btn 1','btn 2'], 'default text')
.then(function(result) {
var input = result.input1;
// no button = 0, 'OK' = 1, 'Cancel' = 2
var btnIndex = result.buttonIndex;
});
// beep 3 times
$cordovaDialogs.beep(3);
});