gpt4 book ai didi

android - deviceready 事件未在 phonegap for android 中触发

转载 作者:行者123 更新时间:2023-11-29 22:56:19 25 4
gpt4 key购买 nike

我编写了简单的 phonegap 应用程序来测试 deviceready:

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
</head>
<body>
<script src="js/main.js"></script>
</body>
<html>

ma​​in.js

window.addEventListener("deviceready", function() {
alert("Device is ready");
});

但是警报永远不会触发。我通过运行添加了android平台

$ phonegap platform add android

在应用程序的根目录(包含 www 文件夹的目录)中,但仍然没有解决问题。我也读过很多关于这个问题的答案( hereherehere ),但没有一个对我有用。可能是什么问题?

编辑:感谢您指出错误。将 deviceReady 更改为 deviceready

最佳答案

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
//**Note:** src is path for cordova.js
<script type="text/javascript" src="js/cordova.js"></script>
</head>
<body>
<script src="js/main.js"></script>
</body>
<html>

主要.js

$(document).ready(function () {
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Alert
}
});

关于android - deviceready 事件未在 phonegap for android 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57411484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com