限制输入监听input的input事件
1.只允许输入数字
this.inputValue = this.inputValue.replace(/[^\d]/g, "")
2.只允许输入数字和小数点
this.inputValue = this.inputValue.replace(/[^\d.]/g, "")
3.只允许输入一个小数点
this.inputValue = this.inputValue.replace(/\.{2,}/g, "")
4.保留两位小数
this.inputValue = this.inputValue.replace( /^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3" )
也可以串联使用
this.inputValue = this.inputValue.replace(/[^\d.]/g, "").replace(/\.{2,}/g, "")