您好,我正在尝试运行一个 javascript 函数(一个测试警报),但它在 index.html 以外的页面中没有触发。
这是一个未触发 javascript 警报的页面示例(请注意,< 已从所有标记中删除,以便在堆栈溢出中呈现):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert("test");
navigator.notification.alert("PhoneGap is working");
}
</script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
<link rel="stylesheet" href="docs/_assets/css/jqm-docs.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
<script src="docs/_assets/js/jqm-docs.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" href="n_style.css" />
</head>
<body onload="onBodyLoad()">
</body>
</html>
最佳答案
onDeviceReady 仅在应用启动时触发一次。请参阅文档: http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#deviceready
它是指示 PhoneGap 已完全加载的函数。
关于javascript - PhoneGap Javascript 除了在索引文件中以外不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7984975/