科尔多瓦对话框插件不起作用



我已经在这个问题上停留了 10+ 个小时,我自己修复它没有运气。问题是我正在尝试在我的 Cordova 应用程序上使用此对话框插件,但它不起作用。我什至不认为设备就绪脚本正在工作。

任何问题都可以随时提出

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>

<plugin name="cordova-plugin-dialogs" spec="^1.3.3" />正在配置中.xml

您在<script>标签中的代码似乎没问题。如果您已使用 - 添加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>

如果仍然不起作用,您可以在谷歌浏览器中检查,查看并在Console选项卡下列出错误消息吗?如果未触发该onDeviceReady(),则在此之前可能会有一些错误<script>

从这里看到错误消息后更新-

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

我重新安装了Windows 10并重新安装了整个Cordova。现在所有插件都可以:)对不起,如果这不是你想要的答案,但它对我有用!祝你今天开心!

最新更新