2016-03-03 60 views
1

科爾多瓦 - 插件的對話框:navigator.notification.prompt不能正常工作

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部分不工作時,用戶按下退出,但如果正確的工作作爲其預期當用戶按確定按鈕。

+0

alert(results.buttonIndex); ...提醒按鈕getindex並檢查... – Banik

+0

我測試了你的代碼,它在Android和iOS上工作正常。你在測試哪個平臺?你確定你正在使用更新的插件嗎? – jcesarmobile

+0

我正在Windows平臺(OS Windows Mobile 10)中測試它。現在工作很好。我的邏輯與我有不同的問題。謝謝。 –

回答

1

你必須檢查buttonIndex類型:

function onPrompt(results) { 
    if (results.buttonIndex === 1) { 
    alert('sucess'); 
    } else { 
    alert('fail'); 
    } 
} 

如果你只使用兩個相同的標誌,1表示TRUE,它總是在你的函數TRUE,因爲buttonIndex有一個值。

+0

嗨,Joerg。感謝您的建議。我也嘗試過===,但沒有使用:( –

1

這個插件爲不同的平臺返回不同的buttonIndex,因爲在某些平臺上這個提醒還有關閉按鈕「x」也在計數,您還應該檢查和平臺。如果我記得這個問題是在iOS上的哪個1關閉按鈕; 2 -ok和3 -exit

相關問題