<input
type="number"
min="0"
max="1"
step="0.01"
@input="change"
v-model="discount"
autocomplete="off"
placeholder="限制輸入0-1的两位小数"
/>
change() {
if (date.discount > 1) {
date.discount = 1;
} else if (date.discount < 0) {
date.discount = 0;
} else if (
date.discount.toString().split(".")[1] &&
date.discount.toString().split(".")[1].length > 2
) {
date.discount = Number(date.discount).toFixed(2);
}
date.discount = date.discount.toString().replace(/^0+\./g, "0."); //把小数0开头的多余0去掉
},
input 输入框限制只能输入0-1的两位小数
最新推荐文章于 2023-10-09 17:11:18 发布