var names = new ContactName();このように、new ContactNameでオブジェクトを生成した後、それぞれのプロパティに値を設定しています。またContactFieldの作成は、
names.givinName = name;
names.familyName = "";
contact.name = names;
contact.emails = [new ContactField('home', mail, false)];このように、type、value、prefの各要素の値をそのまま引数に指定してnew ContactFieldしています。emailsやphoneNumbersは、ContactFieldの配列ですから、作成したオブジェクト1つだけを持つ配列にして設定しておきます。
contact.phoneNumbers = [new ContactField('home', tel, false)];
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
<!DOCTYPE html> <html> <head> <title>My Page</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script> <script type="text/javascript" src="phonegap-1.4.1.js"></script> <script type="text/javascript"> function doAction(){ var dname = document.getElementById('dname').value; var name = document.getElementById('name').value; var mail = document.getElementById('mail').value; var tel = document.getElementById('tel').value; var opt = {'displayName':dname}; var contact = navigator.contacts.create(opt); var names = new ContactName(); names.givinName = name; names.familyName = ""; contact.name = names; contact.emails = [new ContactField('home', mail, false)]; contact.phoneNumbers = [new ContactField('home', tel, false)]; contact.save(); alert('「' + dname + '」のアカウントを作成しました。'); } </script> </head> <body onload="onLoad();"> <!-- home page --> <div id="home" data-role="page"> <div data-role="header"> <h1>Sample</h1> </div> <div data-role="content"> <h2>Sample Page</h2> <div id="msg"></div> <label for="dname">DISPLAY NAME:</label> <input type="text" id="dname"> <label for="name">NAME:</label> <input type="text" id="name"> <label for="mail">MAIL:</label> <input type="text" id="mail"> <label for="tel">TEL:</label> <input type="text" id="tel"> <button onclick="doAction();">Create</button> </div> </div> </body> </html>
<< 前へ |