有问题可以扫码加我微信,有偿解决问题。承接小程序开发。
微信小程序开发交流qq群 173683895 、 526474645 ;
正文:
效果图:
需求:识别文字内的手机号码或者电话号码然后拨打电话
<!--pages/detail/detail.wxml-->
<text>{{data}}</text></view>
<view class='page_bg' wx:if='{{block}}' bindtap='hide_bg'/>
<view class='btn_bg' wx:if='{{block}}'>
<view wx:for="{{phoneNumber}}" wx:key='index'>
<button class="sp_tit" id='{{index}}' bindtap='list_item'>拨打 {{item}} </button>
js
function checkPhone(text) {
return text.match(/((((13[0-9])|(15[^4])|(18[0,1,2,3,5-9])|(17[0-8])|(147))\d{8})|((\d3,4|\d{3,4}-|\s)?\d{7,14}))?/g);
// pages/detail/detail.js
// console.log(checkPhone(phone)) //把字符串检索出来的的数字拆分
var phone_list = checkPhone(phone)
for (var i = 0; i < phone_list.length; i++) {
if (phone_list[i].length == 8 || phone_list[i].length == 7 || phone_list[i].length == 11) {
yse_phone.push(phone_list[i])
if (yse_phone.length == 1) {
phoneNumber: yse_phone[0]
if (yse_phone.length != 0) {
onLoad: function (options) {
list_item: function (e) {
var list_item_phone = this.data.phoneNumber[e.target.id]
phoneNumber: list_item_phone
onPullDownRefresh: function () {
onReachBottom: function () {
onShareAppMessage: function () {
css
/* pages/detail/detail.wxss */
background-color:rgba(0,0,0,0.5);
border-bottom: 1 solid sandybrown;
/* margin: 52rpx auto; */