其他分享
首页 > 其他分享> > H5 input number ,范围限制0.01~99999.99

H5 input number ,范围限制0.01~99999.99

作者:互联网

H5 input number ,范围限制0.01~99999.99

<div class="PriceCenter">
                <p class="competitiveName currencyFont"><span class="required">*</span>价格<span class="numlimit">(0.01~99999.99)</span>:</p>
                <input type="number" @keyUp="handleInput($event)" v-model="brandCompetitor.price" class="competitiveValue" placeholder="请输入价格">
                <span class="Price">元</span>
            </div>

  

,handleInput:function(e) {
            let _this = this;
            let price = _this.price;
            price = price +"";
            price = price.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
            price = price.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            price = price.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            price = price.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
            if (price.indexOf(".") <= 0 && price != "") {//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
                price = parseFloat(price);
            }
            if (price *1>99999.99){
                price = "99999.99";
            }
            _this.price = price;
            console.log(price)
        }

传送门

标签:price,0.01,number,replace,input,H5,99999.99
来源: https://www.cnblogs.com/mafy/p/16668560.html