【问题标题】:Cordova dialog plugin not workingCordova 对话框插件不起作用
【发布时间】:2017-07-05 02:04:52
【问题描述】:

我已经在这个问题上停留了 10 多个小时,而且我自己解决它没有运气。问题是我试图在我的 Cordova 应用程序上使用这个对话框插件,但它不起作用。我什至不认为 deviceready 脚本正在运行。

有什么问题可以问

www/index.html:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Security-Policy" content=".." />
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <link href="css/layout-styles.css" rel="stylesheet" type="text/css">
        <link href="css/bootstrap-3.3.7.css" rel="stylesheet" type="text/css">
        <script src="cordova_plugins.js"></script>
        <script src="cordova.js"></script>
        <script src="js/index.js"></script>
        <script src="js/jquery-3.1.1.min.js"></script>
        <script src="js/bootstrap.js"></script>
        <title>Plugins Not Working</title>

        <script src="cordova.js">

            document.addEventListener("deviceready", onDeviceReady(), false)

            function onDeviceReady() {     
                navigator.notification.alert(
                    'Script has loaded',  // message
                    alertDismissed,       // callback
                    'Loaded',             // title
                    'Done'                // buttonName
                );
            };

            function alertDismissd() {
                // do something
            };

         </script>
    </head>
</html>

&lt;plugin name="cordova-plugin-dialogs" spec="^1.3.3" /&gt; 在 config.xml 中

【问题讨论】:

    标签: javascript android html cordova


    【解决方案1】:

    &lt;script&gt; 标签中的代码似乎没问题。如果您使用 -

    添加了 dialogs 插件
    cordova plugin add cordova-plugin-dialogs
    

    应该可以正常工作。

    并且不要为包含您的代码的脚本添加src="cordova.js"。就这样做 -

    <script>
    document.addEventListener("deviceready", onDeviceReady(), false)
    
    function onDeviceReady() {     
    navigator.notification.alert(
       'Script has loaded',  // message
        alertDismissed,       // callback
        'Loaded',             // title
        'Done'                // buttonName
        );
    };
    
    function alertDismissd() {
         // do something
    };
    
    </script>
    

    如果还是不行,可以inspect in Google Chrome,查看并列出Console标签下的错误信息吗?如果onDeviceReady() 没有被触发,那么在&lt;script&gt; 之前可能会出现一些错误。

    UPDATE 在看到来自here 的错误消息后 -

    1. 删除&lt;script src="cordova_plugins.js"&gt;&lt;/script&gt; 这不是必需的。插件直接从js调用。
    2. Cannot read property 'alert' of undefined => 插件未正确安装。首先在 cmd 中使用cordova plugin add cordova-plugin-dialogs 安装它。
    3. 删除&lt;script src="js/index.js"&gt;&lt;/script&gt;。当您在 &lt;script&gt; 标记内执行所有操作时,您不需要 index.js 或其 js 内容(有错误)。

    【讨论】:

    • 有 3 个错误。生病发送一张图片,以免我输入任何错误:imgur.com/a/nHz9w 这是资产文件夹中的构建版本
    • 谢谢,第一个“cordova 未定义错误”已修复,但其他 2 个仍然存在
    • 好的,第三个错误现在已修复,但我重新安装了对话框插件,但仍然出现该错误。
    • 据我所知应该可以。您可以重建项目并重试吗?
    • 我试过了。我唯一能想到的就是安装旧版本的对话框?
    【解决方案2】:

    我重新安装了 Windows 10 并重新安装了整个 cordova。现在所有插件都可以工作了:) 抱歉,如果这不是您想要的答案,但它对我有用!祝你有美好的一天!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 2016-09-21
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多