代码第09~13行定义了打开手机通讯录的列表,其中第09行代码<li>标签内定义了一个JS脚本方法clicked(this.id),用于打开手机通讯录页面,而“this.id”定义的页面地址就是“plus/contacts.html”。找到“plus”目录下的“contacts.html”页面,具体代码如下:【代码8-5】
01 <! DOCTYPE html> 02 < html> 03 < head> 04 < meta charset=" utf- 8"/> 05 < meta name=" viewport" content=" initial- scale= 1. 0, maximum- scale= 1. 0, user- scalable= no"/> 06 < meta name=" HandheldFriendly" content=" true"/> 07 < meta name=" MobileOptimized" content=" 320"/>
08 < title> HTML 5+ 调用 手机 通讯录</ title> 09 < script type=" text/ javascript" src="../ js/ common. js"></ script> 10 < script type=" text/ javascript"> 11 // 监听 plusready 事件 12 document. addEventListener( "plusready", function(){ 13 // 扩展 API 加载 完毕, 现在 可以 正常 调用 扩展 API 14 plus. contacts. getAddressBook( plus. contacts. ADDRESSBOOK_ PHONE, function (addressbook) { 15 addressbook. find([" displayName"," phoneNumbers"], function( contacts){ 16 alert(" 通讯录 共计: " + contacts. length + "条."); 17 var newLi, newSpan, textNode; 18 for( var i= 0; i< contacts. length; i++) { 19 // contactLi = "<li>< span class=' item'>< div class=' chs'>" + contacts[ i]. displayName + "</div></ span></ li>"; 20 newLi = document. createElement(" li"); 21 newSpan = document. createElement(" span"); 22 newSpan. className = "item"; 23 newDiv = document. createElement(" div"); 24 newDiv. className = "chs"; 25 textNode = document. createTextNode( contacts[
contacts[ i]. displayName); 26 newDiv. appendChild( textNode); 27 newSpan. appendChild( newDiv); 28 newLi. appendChild( newSpan); 29 document. getElementById(" clist"). appendChild( newLi); 30 } 31 }, function () { 32 alert(" error"); 33 },{multiple: true}); 34 },function( e){ 35 alert(" Get address book failed: " + e. message); 36 }); 37 }, false ); 38 </ script> 39 < link rel=" stylesheet" href="../ css/ common. css" type=" text/ css" charset=" utf- 8"/> 40 </ head> 41 < body> 42 < header id=" header"> 43 < div class=" nvtt"> 通讯录</ div> 44 </ header> 45 < div id=" content" class=" content"> 46 < ul id=" clist" style=" list- style: none; margin: 0; padding:
padding: 0; text- align: left;"> 47 < ul> 48 < div> 49 </ body> 50 < script type=" text/ javascript" src="../ js/ immersed. js" ></ script> 51 </ html>