HTML代码:
<input class=‘Input’ type=‘number’ bindinput=‘BankCardNoInput’ value=’{{userInputCardNo}}’></input>
js代码:
Page({
/**
* 页面的初始数据
*/
data: {
winHeight: 0,
money: ‘300.00’,
userInputCardNo2: ‘’,
cardlen: 0,
},
//输入框的监听事件
BankCardNoInput: function (e) {
var card = e.detail.value;
var len = card.length;
if (len > this.data.cardlen) {
if ((len + 1) % 5 == 0) {
card = card + ’ ';
console.log(‘ok’,card)
}
} else {
card = card.replace(/(^\s*)|(\s*$)/g, “”)
}
this.setData({
userInputCardNo: card
})
this.setData({
cardlen: len
})
},