1. 安裝
cordova plugin add cordova-plugin-dialogs
2. index.html添加按鈕
<button id="alert">alert</button>
<button id="confirm">confirm</button>
<button id="prompt">prompt</button>
<button id="beep">beep</button>
3. index.js添加事件
有四種對話框 可以根據自己的需求選擇
document.addEventListener('deviceReady',function(){
document.getElementById('alert').onclick=function(){
navigator.notification.alert('我是消息',function(){
alert("我是回調函數")
},'我是標題','我是按鈕')
}
document.getElementById('confirm').onclick=function(){
navigator.notification.confirm('我是消息',function(index){
alert(index);
if(index===1){
alert("按下按鈕1")
}else if(index===2){
alert("按下按鈕2")
}else if(index===3){
alert("按下按鈕3")
}
},'我是標題',['按鈕1','按鈕2','按鈕3'])
}
document.getElementById('prompt').onclick=function(){
navigator.notification.prompt('我是信息', function(object){
console.log(object)
alert(object.input1)
if(object.buttonIndex===1){
alert("按下按鈕1")
}else if(object.buttonIndex===2){
alert("按下按鈕2")
}else if(object.buttonIndex===3){
alert("按下按鈕3")
}
}, ['標題1','標題2'], ['按鈕1','按鈕2','按鈕3'],'默認文本')
}
document.getElementById('beep').onclick=function(){
navigator.notification.beep(3);
}
})