Web Front-end
H5 Tutorial
Detailed explanation of HTML5 address book to obtain information of specified multiple people
Detailed explanation of HTML5 address book to obtain information of specified multiple people
This article mainly introduces the detailed explanation of HTML5+ address book to obtain the information of multiple specified people. It is of great practical value and friends in need can refer to it.
This article introduces the HTML5 address book to obtain the information of multiple specified people. The details are as follows:
1. Obtaining the information of multiple people: Before importing the information of multiple people in the address book, it is necessary to solve the problem of obtaining information. Information about multiple individuals. I obtained the IDs and displayNames of all contacts in the address book through the application of plus.contacts.getAddressBook and address.find, and then displayed them through the address book acquisition page I wrote.
1. To solve this problem, first you have to write a js address book yourself, so that the initials of all your contacts can be separated, and you can jump to the initials you want next to them.
2. Solve the problem of obtaining all contact information
plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) { //获取通讯录信息
// 可通过addressbook进行通讯录操作
addressbook.find(null, function(contacts) {
var username = new Array();
var LinkList = new LinkedList();
if(contacts.length > 0) { //获取当前通讯录里面所有人
for(var i = 0; i < contacts.length; i ) {
username[i] = contacts[i].displayName "-" contacts[i].id; //连接id和username,为后面筛选最准备
}
//这下面的代码是把所有联系人的信息分类,这就涉及到了自己写的JS页面代码
LinkList = sortPY(username); //把联系人数组分类
//LinkList.show();
createLiCheckBox(LinkList); //分类信息显示至页面,我使用checkBox进行多个联系人选择
}
}, function(e) {
alert("Find contact error: " e.message);
});
}, function(e) {
});2. Import multiple selected personal information from the address book: Solve this problem in the previously created When entering the address book page, the contact's ID must be placed on the page (hidden using display), so that when I obtain the selected checkBox, I can directly obtain the ID and put these IDs into an array. Then filter out the contact information of these IDs through the application of plus.contacts.getAddressBook and address.find.
1. To solve the problem of using checkBox to get the contact id, here I used JQuery.
//筛选已经被选中的checkbox
$("input:checked").each(function() {
var index = $(this).parent().prev().children('label').text(); //获取id
var name = $(this).parent().prev().children('p').text(); //获取姓名
username.push(name);
usernameIndex.push(index);
});2. To solve the problem, put these indexes into find to filter the information, and take out the contact information under the specific ID
plus.contacts.getAddressBook(plus.contacts.ADDRESSBOOK_PHONE, function(addressbook) { //获取通讯录信息
for(var j = 0; j < username.length; j ) {//循环所选取的联系人,记得循环一定要放在这里,一开始我放在 plus.contacts.getAddressBook外面是错误
addressbook.find(null, function(contacts) {
console.log("进入查询");
for(var i = 0; i < contacts.length; i ) {//无论是否为多个信息,一定要循环数组
console.log("进入循环");
//var id = contacts[i].id;
var displayname = contacts[i].displayName;
var phone = "";
var emails = "";
var dates = "";
var remark = "";
if(contacts[i].phoneNumbers.length > 0) {//这里需要判断是否为空,为空的数组没有index=0;
phone = contacts[i].phoneNumbers[0].value;
} else {
phone = contacts[i].phoneNumbers;
}
if(contacts[i].emails.length > 0) {//这里需要判断是否为空,为空的数组没有index=0;
emails = contacts[i].emails[0].value;
} else {
emails = contacts[i].emails;
}
var dateNum = new Date(contacts[i].birthday);//这里的birthday是number类型!!!官方手册坑爹?
dates = dateNum.getFullYear() "." (dateNum.getMonth() 1) "." dateNum.getDate();
remark = contacts[i].note;
var getContact = {//把所有信息放到一个json里面
contactName: displayname,
sex: "",
department: "",
positions: "",
tel: "",
phone: phone,
eMail: emails,
birthday: dates,
hobby: "",
remark: remark
};
//这下面是我的业务代码了,这里大家可以写自己的信息
//createContactTable(db);
//InsertContact(db, getContact); //多个信息插入有线程安全的问题出现!!!!!!!
}
//console.log(username.length);
}, function(e) {
console.log("查询错误");
}, {
//这里面的筛选非常重要!!!这样才能选出匹配的信息
filter: [{
logic: "or",
field: "id",
value: usernameIndex[j]
}],
multi: false
});
}
}, function(e) {
console.log("打开通讯录错误");
});The above is the detailed content of Detailed explanation of HTML5 address book to obtain information of specified multiple people. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Clothoff.io
AI clothes remover
Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
How to restrict file types for an upload input in HTML
Aug 24, 2025 am 02:57 AM
Use the accept attribute to limit the upload type of HTML file, such as accept="image/*" only allows images, accept=".pdf" only allows PDF, accept=".doc,.docx,.pdf,.txt" allows multiple specified types, and can combine JavaScript to verify file types to improve user experience, but security verification must be performed on the server side, because the accept attribute is not secure and the browser supports are different, and it is only used to improve availability rather than replace server verification.
How to disable a form element in HTML
Aug 30, 2025 am 08:45 AM
To disable HTML form elements, you can use the disabled attribute, which can prevent user interaction and the element value will not be submitted with the form. This attribute is of a Boolean type and can be directly added to form element tags such as input, textarea, select, or button. For example, it can also be dynamically controlled through JavaScript, such as document.getElementById("myInput").disabled=true. If the element cannot be edited but the value is still submitted, you should use the readonly attribute. The disabled attribute is simple and effective and widely supported.
How to use the HTML5 contenteditable attribute
Aug 23, 2025 am 09:55 AM
ThecontenteditableattributemakesHTMLelementseditablebyaddingcontenteditable="true"toelementslikediv,p,orh1–h6.2.UseJavaScripttoretrievecontentviainnerHTMLforformattedtextortextContentforplaintext.3.Listenforchangesusingtheinputeventtocaptur
How to add a favicon to your website with HTML5
Aug 27, 2025 am 02:35 AM
To add a website favicon correctly, first prepare a 32×32 or 64×64 pixel .ico, .png or .svg format icon file and name it favicon.ico, etc., place it in the website root directory or a specified path, and then use a clear statement in the HTML tag. For example: It is recommended to support multiple formats and devices at the same time, such as adding PNG different size versions, SVG icons, and Apple touch icons. Finally, clear the cache and test whether it displays normally, to ensure that the path is correct and the file is accessible. The entire process requires attention to the file format, path and compatibility to avoid loading failure.
What is the importance of the alt attribute for images in HTML5?
Aug 27, 2025 am 02:29 AM
Thealtattributeisessentialforaccessibility,SEO,anduserexperience;1.Itenablesscreenreaderstodescribeimagestovisuallyimpairedusers,ensuringcontentcomprehension;2.Itdisplaysfallbacktextwhenimagesfailtoload,maintainingcontext;3.ItimprovesSEObyhelpingsear
What is ARIA in HTML for accessibility?
Aug 27, 2025 am 04:57 AM
ARIAisneededtoenhancewebaccessibilityfordynamiccontentandcustomUIcomponentsthatlacknativeHTMLsemantics.1)ARIArolesdefineanelement’spurpose(e.g.,role="dialog").2)ARIApropertiesdescribecharacteristics(e.g.,aria-label,aria-describedby).3)ARIAs
What is the placeholder attribute's purpose in HTML5?
Aug 31, 2025 am 06:58 AM
Theplaceholderattributeprovidesashorthintininputfieldsthatdisappearswhentypingbegins;1.Itisusedinandelementstoshowexampletextlike"Enteryouremail";2.Thehintisdisplayedonlywhenthefieldisemptyandstyledfaintlybybrowsers;3.Itdoesnotreplacetheele
How does Content Security Policy (CSP) work with HTML5?
Aug 30, 2025 am 01:29 AM
CSPenhancesHTML5securitybydefiningtrustedcontentsourcestopreventXSS,clickjacking,andcodeinjection.1.Itrestrictsinlinescriptsandstylesbyblockingthemunless'unsafe-inline',nonces,orhashesareused.2.Itcontrolsexternalresourcesviadirectiveslikescript-src,i


