// 解决首位直接输入 '0开头的数字'问题 this.inputModel = this.inputModel.toString() + curVal.toString() this.inputModel = this.inputModel.replace(/[^\d.]/g,""); //清除“数字”和“.”以外的字符 this.inputModel = this.inputModel.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的 this.inputModel = this.inputModel.replace(".","$#$").replace(/\./g,"").replace("$#$","."); this.inputModel = this.inputModel.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3') //保留2位小数 if(this.inputModel.indexOf(".")< 0 && this.inputModel !=""){//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 this.inputModel= parseFloat(this.inputModel); } //判断不能输入最大值 if(this.maxValue > 0 && this.maxValue < this.inputModel) { this.inputModel = this.maxValue } const inputVal = this.inputModel const len = inputVal.length if(len == 1 && inputVal.charAt(0) == '.') { this.inputModel = '' }