2012-02-14 13 views
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> 

結果にいくつかの問題があります:は「はconsole.log」日食にAndroidのシミュレータで

loadingPhoneGap PhoneGapのは、連絡先を作成例 をロード

「警告」がありません、それが見えましたその機能がうまくいかない、問題は何ですか?

答えて

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>