我已经在这个问题上陷入了 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>
<plugin name="cordova-plugin-dialogs" spec="^1.3.3" />
位于 config.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>
如果还是不行,可以 inspect in Google Chrome ,查看并列出 Console
下的错误消息标签?在此之前可能存在一些错误<script>
如果是onDeviceReady()
未触发。
更新在看到来自 here 的错误消息后-
- 删除
<script src="cordova_plugins.js"></script>
那不是必需的。插件直接从js
调用. -
Cannot read property 'alert' of undefined
=> 插件未正确安装。首先使用cordova plugin add cordova-plugin-dialogs
安装它在cmd中。 - 删除
<script src="js/index.js"></script>
。当你在里面做所有事情时<script>
标签,你不需要index.js
或其js
内容(有错误)。
关于javascript - Cordova 对话框插件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44916017/