<el-input keyup.native="isFloor"/>
//正數,含小數 isFloor(e,type){ if(type=='floor') { var val=e.target.value; //限制只能輸入一個小數點 if (val.indexOf(".") != -1) { var str = val.substr(val.indexOf(".") + 1); if (str.indexOf(".") != -1) { val = val.substr(0, val.indexOf(".") + str.indexOf(".") + 1); } } e.target.value = val.replace(/[^\d^\.]+/g,''); } }, //正負數,含小數 isFloor(){ var obj=event.target; var t = obj.value.charAt(0); obj.value = obj.value.replace(".", "$#$")//把第一個字符'.'替換成'$#$' .replace(/\./g, "")//把其余的字符'.'替換為空 .replace("$#$", ".")//把字符'$#$'替換回原來的'.' .replace(/[^\d.]/g, "")//只能輸入數字和'.' .replace(/^\./g, "")//不能以'.'開頭 .replace( /([0-9]+\.[0-9]{2})[0-9]*/,"$1")//只保留2位小數 if (t == '-') { obj.value = '-' + obj.value; } }
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com