utils:
/** * 输入内容小数检测 * @ndata 输入的小数 * @odata 输入前的小数 */ function doubleData(ndata, odata) { let result = 0; var numSplit = ndata.split("."); if (numSplit.length - 1 > 1) { result = odata;//有多余小数点 } else { if (numSplit.length - 1 == 1) { if (numSplit[1].length > 2) { result = odata;//小数超过两位 } else { result = ndata; } if (numSplit[0].length == 0) {//点前没有数值 result = "0" + result; } } else { result = ndata; } } return result; }
module.exports = {
doubleData: doubleData,
}
js:
data{
payNumebr : 0;
}
paynumber(e) {
let payNumebr = e.detail.value;
let dataPayNumebr = this.data.payNumebr
let thisPayNumebr = util.doubleData(payNumebr, dataPayNumebr);
this.setData({
payNumebr: thisPayNumebr
})
},
wxml
<input type="digit" placeholder="输入支付金额" value="{{payNumebr}}" bindinput="paynumber"></input>