“console.log”存在一些问题

时间:2012-02-14 10:32:13

标签: android eclipse cordova

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/ html; charset=utf-8" />
<title>Contact Example</title>

<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">

document.write("loading PhoneGap");
document.addEventListener("deviceready", onDeviceReady, false);

document.write("PhoneGap loaded");
function onDeviceReady() {
alert("begin");
var myContact = navigator.service.contacts.create({"displayName": "Test User"});
myContact.gender = "male";
document.write("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender");
alert("end");
}  

</script>
</head>
<body>
 <h1>Example</h1>
 <p>Create Contact</p>
</body>
</ html>

eclipse上Android模拟器的结果是:

loadingPhoneGap PhoneGap已加载 例 创建联系人

“警报”缺失,似乎该功能无法正常工作,问题是什么?

2 个答案:

答案 0 :(得分:0)

警报功能可能不是本机支持的,您可以尝试使用phonegap警报吗?

http://docs.phonegap.com/en/1.0.0/phonegap_notification_notification.md.html#notification.alert

答案 1 :(得分:0)

应该是:

navigator.contacts.create

不是

navigator.service.contacts.create

此外,您还有一些JavaScript订购问题。这是一个完整的工作index.html:

    <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/ html; charset=utf-8" />
<title>Contact Example</title>

<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>

<script type="text/javascript" charset="utf-8">

var onDeviceReady = function() {
alert("begin");
var myContact = navigator.contacts.create({"displayName": "Test User"});
myContact.gender = "male";
alert("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender");
alert("end");
};

document.write("loading PhoneGap");
document.addEventListener("deviceready", onDeviceReady, false);

document.write("PhoneGap loaded");



</script>
</head>
<body>
 <h1>Example</h1>
 <p>Create Contact</p>
</body>
</html>
相关问题