学无先后,达者为师

网站首页 编程语言 正文

利用keyup事件实现input框输入0-1之间的数字且最多只能保留2位小数

作者:文仔酱酱酱 更新时间: 2023-07-24 编程语言
<Input  type="tel"  v-model="user.limitPricezk" style="width: 300px"  placeholder="最低修改商品价格折扣" maxlength='4' @on-keyup="restrictInp"></Input>
restrictInp(e){
                 var reg = /^(0.\d+|0|1)$/;
                    if (reg.test(e.target.value)) {
                        this.user.limitPricezk = e.target.value;
                    } else {
                        if (e.target.value != "0.")
                        this.user.limitPricezk = "";
                    }
            },

注意一个问题 设置input属性为number时maxlength不生效,将属性设置为tel

原文链接:https://blog.csdn.net/baidu_41899377/article/details/125146378

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新