我是phonegap和javascript html的初学者。我不知道为什么事件设备没有激活并且onload没有执行。请帮帮我,谢谢。
<html>
<head>
<title>My Device</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
// Use an event listener to detect if PhoneGap is ready
//
function onLoad() {
console.log("onload");
document.addEventListener("deviceready", onDeviceReady, false);
}
// okay, PhoneGap is ready
//
function onDeviceReady() {
console.log("deviceReady");
}
</script>
</head>
<body onload="onLoad()">
<p id="props">Loading device properties...</p>
</body>
</html>
答案 0 :(得分:0)
你在“onload”回调中绑定了onauready,可以在调度ondeviceready之后调度它。
因此,您应该直接绑定事件。请参阅示例:http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#deviceready
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the PhoneGap API
}
</script>