我已经被困在这个问题上超过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
答案 0 :(得分:1)
<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()
之前可能会出现一些错误。
更新
<script src="cordova_plugins.js"></script>
不需要。插件直接从js
。Cannot read property 'alert' of undefined
=&gt;该插件未正确安装。首先使用cmd中的cordova plugin add cordova-plugin-dialogs
安装它。<script src="js/index.js"></script>
。当您在<script>
标记内执行所有操作时,您不需要index.js
或其js
内容(有错误)。答案 1 :(得分:0)
我重新安装了Windows 10并重新安装了cordova。现在所有的插件都可以工作:)对不起,如果这不是你想要的答案,但它对我有用!祝你有个美好的一天!