function onPrompt(results) {
if (results.buttonIndex == 1) {
alert('sucess');//working
} else {
alert('fail');//not working
}
}
navigator.notification.prompt(
'Please enter your name',
onPrompt,
'Registration',
['Ok', 'Exit'],
'Maruthi'
);
当用户按退出时,onprompt() else部分不起作用,但是当用户按确定按钮时,如果按预期正常工作。
您必须检查 buttonIndex 的类型:
function onPrompt(results) {
if (results.buttonIndex === 1) {
alert('sucess');
} else {
alert('fail');
}
}
如果只使用两个等号,则 1 表示 TRUE,这在函数中始终为 TRUE,因为 buttonIndex 有一个值。
此插件为不同的平台返回不同的按钮索引,因为在某些平台中,此警报也有关闭按钮"x",它也在计数,您还应该检查和平台。如果我记得这个问题是在 iOS 上,其中 1 关闭按钮;2 -正常和 3 -退出