Javascript Cordova中的确认对话框
我正在使用phonegap/cordova用javascript和html编写一个应用程序。 我有以下javascript代码:Javascript Cordova中的确认对话框,javascript,jquery,cordova,Javascript,Jquery,Cordova,我正在使用phonegap/cordova用javascript和html编写一个应用程序。 我有以下javascript代码: $('#diario_delete_btn').live('tap',function(e){ var iddb = $(this).find('a').attr('rel'); confirm_diario_delete(iddb); }); function diario_delete(iddb) { var db = w
$('#diario_delete_btn').live('tap',function(e){
var iddb = $(this).find('a').attr('rel');
confirm_diario_delete(iddb);
});
function diario_delete(iddb) {
var db = window.openDatabase("Database", "1.0", "123nozze", 200000);
db.transaction(function(tx){
tx.executeSql('DELETE FROM AgendaItemJDO WHERE id='+iddb);
lastChangeUpdate();
});
$('.diario_row[db_id="'+ iddb +'"]').remove();
$('#popupMenuDiario').popup("close");
}
function confirm_diario_delete(iddb) {
var r = confirm("Confermi l'eliminazione dell'elemento?");
if (r) {
diario_delete(iddb);
} else {
$('#popupMenuDiario').popup("close");
}
}
它似乎可以工作,但如果我在按下“确认按钮”之前选择了“取消按钮”(因此r=false)n次,则下次显示确认对话框2次,下次显示3次,依此类推。我不知道为什么会这样。如果更改代码,我将使用Cordova示例代码进行确认对话框,情况也是如此
有没有关于问题是什么以及如何解决的想法?
谢谢 您应该使用Phonegap支持的本机
特别是从上面的链接中获取的.confirm()方法
// process the confirmation dialog result
function onConfirm(button) {
alert('You selected button ' + button);
}
// Show a custom confirmation dialog
//
navigator.notification.confirm(
'You are the winner!', // message
onConfirm, // callback to invoke with index of button pressed
'Game Over', // title
'Restart,Exit' // buttonLabels
);
如何在确认按钮之前按n次取消按钮?当我按下“取消”按钮时,对话框立即消失,我没有时间多次按下它。你是不是在以超人的速度敲击按钮?你在什么设备上测试这个?另外,您应该使用通知插件,因为Cordova/Phonegap使用确认、提示等将消息从javascript传递到本机代码。(确认、提示等,可能有效,但不安全。)试一下,我会尽快尝试。无论确认对话框如何出现,我选择了取消按钮,它会取消,然后重新出现。如果你点击取消按钮,它不会重新出现。您是否可以尝试创建一个非常简单的确认对话框,看看是否可以在没有jQuery的情况下重现该行为?我在想,也许你的jquery代码有点愚蠢,但它看起来并没有错(虽然我不使用jquery…)对于这段代码,我也有同样的问题,而且它没有执行onConfirm函数。如果没有显示confirm,它就不会触发confirm,因此有东西阻止了警报的显示。如果将控制台日志放在navigator.notification.confirm()之前,它是否会输出到控制台?
navigator.notification.confirm(
'Are you sure you want to signup ', // message
onConfirm, // callback to invoke with index of button pressed
'SignUp', // title
['yes','no'] // buttonLabels
);
function onConfirm(buttonIndex){
alert('You selected button ' + buttonIndex);
if(buttonIndex==2){
alert('You selected button - no');
}else{
alert('You selected button - yes');
}
}