// 去掉字符串中所有空格(包括中间空格,需要设置第2个参数为:g)
function trim(str, is_global) {
var result;
result = str.replace(/(^\s+)|(\s+$)/g, "");
if (is_global && is_global.toLowerCase() == "g") {
result = result.replace(/\s/g, "");
}
return result;
}
// 判断是否是手机号码格式
function isPhone(str) {
var reg = /^1(3|4|5|7|8)\d{9}$/;
return reg.test(trim(str, 'g'));
}
// 手机号码格式转化为 344 格式 (188 3886 9199)
function phoneSeparated(phoneNumber) {
let tel = trim(phoneNumber, 'g');
if (isPhone(tel)) {
tel = tel.substring(0, 3) + ' ' + tel.substring(3, 7) + ' ' + tel.substring(7, 11);
}
return tel;
}
phoneSeparated("18838869199") // "188 3886 9199"
1、wxml
bindtap="pay_again" data-name="{{orderList.jid}}" data-fee="{{orderList.act_fee}}" data-mobile="{{orderList.p_phone}}" data-act="{{orderList.act_name}}" class="operating f_r webkit-box" style="line-height:30px;">
href="" class="pay bg_red">继续支付
2、js
// 再次发起支付请求,调用后台PHP
pay_again:function(e){
var that = this;
that.setData({
jid: e.currentTarget.dataset.name,
act_name: e.currentTarget.dataset.act,
act_fee: e.currentTarget.dataset.fee,
mobile: e.currentTarget.dataset.mobile
})
console.log('活动订单id = ' + that.data.mobile);
}
3、动态改变样式
作者:奋斗放个
data: {
coatFatThinColor: '#999',
}
<view style="color:{{coatFatThinColor}}" class="ui-flex picker-select ui-padding-10">
this.setData({
coatFatThinColor: '#000'
})