限制只能输入整数
关键代码:
只能输入整数: oninput="this.value = this.value.replace(/[^0-9]/g, '');"
只能输入整数且长度小于7: oninput="if( this.value.length > 7 ) {this.value = this.value.slice(0,7)} else {this.value = this.value.replace(/[^0-9]/g, '')}"
可以输入小数: oninput="this.value = this.value.replace(/[^0-9.]/g, '');"
只能输入正数: onkeyup="this.value=this.value.replace(/\D/g,'')"
只能输入正数、小数: onkeyup="this.value=this.value.replace(/[^\d.]/g,'')"
只能输入正数、小数、负数: this.value=this.value.replace(/[^-?\d.]/g,'')"
<el-input type="text" oninput="this.value = this.value.replace(/[^0-9]/g, '');" :readonly="dialog.showDetail" clearable placeholder="请填写上月表数" v-model="dialog.form.lastRecordData" @blur="computeDiffer(dialog.form.lastRecordData, dialog.form.newRecordData, 0)" @input="computeDiffer(dialog.form.lastRecordData, dialog.form.newRecordData, 0)"
maxlength="20"></el-input>
通过设置input类型为number类型并且限制其输入长度:oninput="if( this.value.length > 4 ) this.value = this.value.slice(0,4)"
<el-input type="number" :readonly="dialog.showDetail || dialog.status === 'detail'" placeholder="数量" v-model="scope.row.num" oninput="if( this.value.length > 4 ) this.value = this.value.slice(0,4)></el-input>
标签:el,oninput,slice,elemenut,value,replace,只能,input,输入
From: https://www.cnblogs.com/sglblog/p/16737181.html