科尔多瓦事件不起作用,我做错了什么

时间:2017-04-16 12:53:56

标签: javascript android jquery cordova

我的代码如下,它不能在我的Android设备上运行,我希望实现这一点 -

  1. 当我的应用即将最小化时,应该说alert("bye");
  2. 当我再次打开我的应用程序(前提是它在后台运行)时,alert("resume");
  3. 第一次打开时,alert("device ready");
  4. 我以为我已经做好了一切,但不确定我错在哪里。请帮忙

    // example.js file
    // Wait for device API libraries to load
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }
    
    // device APIs are available
    //
    function onDeviceReady() {
        alert("device ready");
        document.addEventListener("pause", onPause, false);
        document.addEventListener("resume", onResume, false);
        document.addEventListener("menubutton", onMenuKeyDown, false);
        document.addEventListener("backbutton", onBackKeyDown, false);
        // Add similar listeners for other events
    }
    
    
    
    function onPause() {
        // Handle the pause event
        alert("pause");
    }
    
    function onResume() {
        // Handle the resume event
        alert("resume");
    }
    
    function onMenuKeyDown() {
        // Handle the menubutton event
        alert("menu key down");
    }
    
    
    function onBackKeyDown() {
        // Handle the onBackKeyDown event
        alert("back key down");
    }
    
    // Add similar event handlers for other events
    <!DOCTYPE html>
    <html>
        <head>
        <title>Device Ready Example</title>
    
        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
        <script type="text/javascript" charset="utf-8" src="index.js"></script>
        </head>
        <body onload="onLoad()">
        </body>
    </html>

2 个答案:

答案 0 :(得分:0)

您可以尝试在javascript中使用:

  window.onload = function() { 
 onLoad();
 }

答案 1 :(得分:0)

检查控制台是否有任何错误。

同时检查您的JavaScript文件的路径是否正确。例如,确保index.js与index.html在同一文件夹中,而不是在单独的js文件夹中。

相关问题