我的代码如下,它不能在我的Android设备上运行,我希望实现这一点 -
alert("bye");
alert("resume");
alert("device ready");
我以为我已经做好了一切,但不确定我错在哪里。请帮忙
// example.js file
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
alert("device ready");
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
document.addEventListener("menubutton", onMenuKeyDown, false);
document.addEventListener("backbutton", onBackKeyDown, false);
// Add similar listeners for other events
}
function onPause() {
// Handle the pause event
alert("pause");
}
function onResume() {
// Handle the resume event
alert("resume");
}
function onMenuKeyDown() {
// Handle the menubutton event
alert("menu key down");
}
function onBackKeyDown() {
// Handle the onBackKeyDown event
alert("back key down");
}
// Add similar event handlers for other events
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="index.js"></script>
</head>
<body onload="onLoad()">
</body>
</html>
答案 0 :(得分:0)
您可以尝试在javascript中使用:
window.onload = function() {
onLoad();
}
答案 1 :(得分:0)
检查控制台是否有任何错误。
同时检查您的JavaScript文件的路径是否正确。例如,确保index.js与index.html在同一文件夹中,而不是在单独的js文件夹中。