小程序点击拨号功能

index.wxml里代码如下

<button bindtap="open">点击拨号</button>

只需要添加一个触发按钮即可

然后index.js里添加一个函数

open: function () {
    wx.showActionSheet({
      itemList: ['400-900-2250'],
      success: function (res) {
        console.log(res) //当点击400-900-2250就相当于点击了
        wx.makePhoneCall({
          phoneNumber: '400-900-2250', //此号码并非真实电话号码,仅用于测试  
          success: function () {
            console.log("拨打电话成功!")
          },
          fail: function () {
            console.log("拨打电话失败!")
          }
        })
        if (!res.cancel) {
          console.log(res.tapIndex)//console出了下标
        }
      }
    });
  }

然后就可以,有问题的话可以留言提问哦

猜你喜欢

转载自www.cnblogs.com/zddzz/p/10019888.html
今日推荐