elemenut的el-input限制只能输入数字

限制只能输入整数

关键代码:
只能输入整数: 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-input-number标签限制数值大小

<el-input-number v-model="weekRealMoney" type="number" :precision="2" :controls="false" :min="0" :max="999999999" placeholder="金额"></el-input-number>
posted @ 2023-04-07 17:00  爱吃糖的橘猫  阅读(3128)  评论(0编辑  收藏  举报