小编Sal*_*man的帖子

如何使javascript函数在另一个完成后运行?

我正在使用Apache Cordova开发移动应用程序.问题是我想获得手机号码然后通过jQuery get函数发送它以进行授权.所有功能都可以,但获取手机号码的功能比其他功能慢,最后完成.

我的代码摘要是这样的:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    devicePhoneNumber();
    alert("ALERT1"); // ALERT1
};
function devicePhoneNumber() {
    var telephoneNumber = cordova.require("telephonenumber");
    telephoneNumber.get(function (result) {
    alert(result); //ALERT2
    }, function () {
        alert("error");
    });
};
Run Code Online (Sandbox Code Playgroud)

我不知道为什么先得到ALERT1然后我得到ALERT2.我得到ALERT2后想运行其他代码.

任何建议将不胜感激.

javascript jquery cordova

5
推荐指数
1
解决办法
207
查看次数

创建一个在手机上安装应用程序后仅触发一次的功能

我正在使用ApacheCordova/Phonegap开发移动应用程序.我需要一个功能,每次安装时都会向我发送一次短信.如果我将我的功能放在"DeviceReady"上,它将在每次应用程序打开时运行.在安装应用程序或第一次运行时,是否有任何解决方案可以运行该功能?

任何建议将不胜感激.

android cordova multi-device-hybrid-apps visual-studio-cordova

4
推荐指数
2
解决办法
2967
查看次数