我在我的 PhoneGap 应用程序中使用了以下代码。
function registrationCallBack(button){
if(button == 2) {
window.location.href = "login.html";
}
}
navigator.notification.confirm("Are you sure ?", registrationCallBack, "Confirmation", "Cancel, Ok");
按钮的顺序在 iPhone 中正确显示为“取消”和“确定”。 但对于 Android,按钮的顺序是相反的。它以“确定”的形式出现,然后是“取消”。
因此,按钮索引在回调方法中发生了变化。
欢迎所有建议:)
谢谢,
最佳答案
尝试使用以下解决方案:
function showConfirm(message, callback, buttonLabels, title){
//Set default values if not specified by the user.
buttonLabels = buttonLabels || 'OK,Cancel';
title = title || "default title";
//Use Cordova version of the confirm box if possible.
if(navigator.notification && navigator.notification.confirm){
var _callback = function(index){
if(callback){
callback(index == 1);
}
};
navigator.notification.confirm(
message, // message
_callback, // callback
title, // title
buttonLabels // buttonName
);
//Default to the usual JS confirm method.
}else{
invoke(callback, confirm(message));
}
}
下面是您将如何使用它:
var message = "Would you like to proceed?";
var title = "Important Question";
//The first element of this list is the label for positive
//confirmation i.e. Yes, OK, Proceed.
var buttonLabels = "Yes,No";
var callback = function(yes){
if(yes){
alert('Proceed');
}else{
alert('Do Not Proceed');
}
};
showConfirm(message, callback, buttonLabels, title);
关于android - PhoneGap 框架中 navigator.notification.confirm 中的按钮顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9819851/