在phonegap中如何通过navigator.notification.alert()在回调函数中传递参数

时间:2016-01-22 14:09:53

标签: javascript jquery cordova phonegap-plugins

function alertDismissed(tag_name) { // This is callback function
    tag_name.focus();
}

function showAlert(msg, callbackfn) {
    navigator.notification.alert(
        'Please enter email',          // message
        alertDismissed:'callbackfn',   // callback
        'App name',                    // title
        'Ok'                           // buttonName
    );
}

我想将参数传递给alertDismissed()函数。我这样称呼它:

UserName=document.getElementById("name-txt").value;
if(UserName == "" || UserName == null)
{
    showAlert("Please enter email","name-txt");
}

实际上,点击“确定”按钮后我想要焦点。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

你可以这样做

function showAlert(msg, callbackfn) {
    navigator.notification.alert(
        'Please enter email',          // message
        function () {
           console.log(callbackfn);
        },   // callback
        'App name',                    // title
        'Ok'                           // buttonName
    );
}