Phonegap deviceready事件不会在设备上触发

时间:2013-05-18 11:02:06

标签: javascript jquery cordova phonegap-build

我正在开发一款移动应用,但我在手机上遇到了一些问题。我很开心,但是当我阅读时,我只需插入这一行即可使用phonegap的功能。

<script src='phonegap.js'></script>

我不确切知道deviceready事件是什么部分。我尝试使用jquery,hammer和NO jquery mobile构建应用程序。

我的问题是deviceready事件不会触发。我尝试了很多方法,如何绑定事件监听器,但我失败了。

我试图像这样绑定:

document.addEventListener('deviceready', ondeviceready);
function ondeviceready(){
    alert('wooohooo');
}
像这样:

$(document).ready(function(){
    document.addEventListener('deviceready', ondeviceready);
});

function ondeviceready(){
    alert('wooohooo');
}

并且像这样:

$(document).on('deviceready',ondeviceready);
function ondeviceready(){
    alert('wooohooo');
}

有人能帮助我吗?

(我在三星Galaxy s&amp; samsung galaxy note 2上测试了应用程序)

2 个答案:

答案 0 :(得分:1)

最后,我不知道为什么,但它对我有用。

function ondeviceready(){...}
document.addEventListener("deviceready", ondeviceready);

答案 1 :(得分:0)

试试这个

document.addEventListener("deviceready", function(){
                      alert('hello');
                      });

或尝试将代码放入以下方法

    this.init = function(){

}

你还在使用phonegap.js下载最新版本的phonegap并使用cordova.js