插件除了从控制台外没有运行:无法执行' alert'未定义的

时间:2014-06-03 21:00:36

标签: javascript cordova

我已经为cordova安装了一个diaglog插件。当我运行它时,我得到一个错误,说“无法调用方法'警报'未定义”。

当我从控制台执行相同的功能时,它运行得很好。

这是我的index.html文件:

<html>
  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="plugins/org.apache.cordova.dialogs/www/notification.js"></script>
    <script type="text/javascript">
    $( document ).ready(function() {

        navigator.notification.alert( <--------------------- here!!
        'You are the winner!',  // message
        function(){

        },         // callback
        'Game Over',            // title
        'Done'                  // buttonName
        );

      });
    </script>
    <LINK rel="stylesheet" href="style.css" type="text/css"> 
  </head>
  <body >
    <div> hello world</div>
  </body>
</html>

1 个答案:

答案 0 :(得分:2)

您需要等待DeviceReady Event

该插件未在

中初始化
  

(文档)$。就绪();

文档已加载 - &gt;文件准备好了 - &gt; cordova开始初始化 - &gt; deviceready