“console.log”存在一些问题

发布于 2025-01-04 23:28:09 字数 995 浏览 0 评论 0原文

<!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已加载 例子 创建联系人

“警报”缺失,似乎该功能不起作用,请问是什么问题?

<!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>

The result in the Android's simulator on eclipse is:

loadingPhoneGap PhoneGap loaded
Example
Create Contact

"alert" is missing, it seemed that that function did not work, what is the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的味道 2025-01-11 23:28:09

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

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

It is possible the alert function might not be natively supported, can you try using the phonegap alert instead?

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

浅紫色的梦幻 2025-01-11 23:28:09

它应该是:

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>

It should be :

navigator.contacts.create

not

navigator.service.contacts.create

Also, you have a few JavaScript ordering issues. Here is a complete working 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文