资料
拨打电话: wx.makePhoneCall(Object object)
显示操作菜单:wx.showActionSheet(Object object)
1.简单操作,知道电话,且只有一个
//wxml
<view bindtap="callPhone">400-4000-4512</view>
phoneNumber:必须是string类型
//js
//直接运用微信小程序中的wx.makePhoneCall来进行操作
callPhone: function(e) {
wx.makePhoneCall({
//phoneNumber:必须是string类型
phoneNumber:"400-4000-4512", //不是真实号码
})
}
微信开发者工具中效果图:

实际手机则是直接跳转到拨号页面:

2.号码有多个的时候
//wxml
<view data-tel="15800434300/4008888888" bindtap="callPhone">15800434300/4008888888</view>
wx.showActionSheet 的参数itemList必须是数组,函数回调成功,只能获取到tapIndex(用户点击的按钮序号,从上到下的顺序,从0开始)
//js
callPhone: function (e) {
var that = this;
//获取data值
var tels = e.currentTarget.dataset.tel;
//tel:15800434300/4008888888
//字符串转换成数组
var phone = tels.split('/')
//phone: ["15800434300", "4008888888"]
wx.showActionSheet({
itemList: phone,
success: function (res) {
wx.makePhoneCall({
phoneNumber: phone[res.tapIndex],
//获取phone数组中的第tapIndex个值
})
}
});
}
效果图;

网友评论