
本文实例讲述了微信小程序实现添加手机联系人功能。分享给大家供大家参考,具体如下:
1、效果展示


2、关键代码
1)WXML文件
<view bindlongtap="phoneNumTap">{{phoneNum}}</view>2)JS文件
Page({
data:{
phoneNum:'123456701'//测试用的号码,并非真实号码
},
// 长按号码响应函数
phoneNumTap:function(){
var that=this;
// 提示呼叫号码还是将号码添加到手机通讯录
wx.showActionSheet({
itemList: ['呼叫','添加联系人'],
success:function(res){
if(res.tapIndex===0){
// 呼叫号码
wx.makePhoneCall({
phoneNumber: that.data.phoneNum,
})
}else if(res.tapIndex==1){
// 添加到手机通讯录
wx.addPhoneContact({
firstName: 'test',//联系人姓名
mobilePhoneNumber: that.data.phoneNum,//联系人手机号
})
}
}
})
}
})3)WXSS文件
view{
color: blue;
padding: 15px;
border-bottom: 1px solid gainsboro;
}上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
有关js事件的循环机制(详细教程)
使用javascript如何实现QQ空间相册展示
如何自定义PC微信扫码登录
有关jade模板引擎的使用详情
有关JS希尔排序算法(详细教程)
