小程序js只能输入数字和2位小数点
作者:xlnxin发布时间:2026-06-07分类:编程知识浏览:4929
导读:<inputbindinput="getPrice"class="input"placeholder="0.00&qu...
<input bindinput="getPrice" class="input" placeholder="0.00" type="digit" value="{{valPrice}}"></input>
js代码
getPrice(e) {
var value = e.detail.value;
value = value.replace(/[^0-9.]/g, '');
value = value.replace(/(\..*)\./g, '$1');
value = value.replace(/(\..{2}).*$/, '$1');
this.setData({
valPrice: value,
})
},
- 编程知识排行
- 最近发表
