我想使用 phonegap Cordova 2.0 创建 iPhone 应用程序。现在i wrote Javascript external and HTML code
。然后我把JavaScript code into the HTML5 file
. 现在我想在网络浏览器上运行 HTML 文件。当我在浏览器中运行 HTML 时,Javascript 不起作用。浏览器显示 HTML 中的任何内容。所以你能帮我吗run the HTML5 file with JavaScript on the browser and in XCode Phonegap
?
下面的编码是 JavaScript 编码。
var bodyLoaded = function()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
// Cordova is ready
//
function onDeviceReady() {
var options = new ContactFindOptions();
options.filter="";
filter = ["displayName","organizations"];
navigator.contacts.find(filter, onSuccess, onError, options);
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
for (var j=0; j<contacts[i].organizations.length; j++) {
alert("Pref: " + contacts[i].organizations[j].pref + "\n" +
"Type: " + contacts[i].organizations[j].type + "\n" +
"Name: " + contacts[i].organizations[j].name + "\n" +
"Department: " + contacts[i].organizations[j].department + "\n" +
"Title: " + contacts[i].organizations[j].title);
}
}
};
// onError: Failed to get the contacts
//
function onError(contactError) {
alert('onError!');
}
下面的编码位于我的 HTML5
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Contact Example</title>
<script type="text/javascript" charset="utf-8" src="Contectscript.js"></script>
</head>
<body>
<body onload='alert(1);'>
<body onload='bodyLoaded();'>
<h1>Example</h1>
<p>Find Contacts</p>
</body>
</html>
提前致谢。