onDeviceReady not firing in PhoneGap hello world app

后端 未结 4 2012
梦如初夏
梦如初夏 2020-11-30 16:05

I\'m trying to do a simple alert(\'test\') app, but the event isn\'t being fired, this is the code:

function onLoad() {
    document.addEventListener("de         


        
4条回答
  •  情歌与酒
    2020-11-30 16:12

    The correct way is to make sure that document has completely loaded before adding the event listener.

    Example:

    HTML:

    
    

    JS:

    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }
    
    function onDeviceReady() {
       //anything you want done after deviceready has fired
    }
    

    With jQuery you can use $(document).ready() instead of

    Example:

    $(document).ready() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }
    
    function onDeviceReady() {
       //anything you want done after deviceready has fired
    }
    

提交回复
热议问题