el-input 限制输入框只能输入数字和小数
oninput =“value=value.replace(/[^\d]/g,’’)”//只能输入数字oninput =“value=value.replace(/[^0-9.]/g,’’)” //只能输入数字和小数<el-input v-model="sjje" oninput ="value=value.replace(/[^0-9.]/g,'')" class="money ...
·
1、纯输入框
方法一:
oninput =“value=value.replace(/[^\d]/g,‘’)” //只能输入数字
oninput =“value=value.replace(/[^0-9.]/g,‘’)” //只能输入数字和小数
<el-input v-model="sjje" oninput ="value=value.replace(/[^0-9.]/g,'')" class="money sjje">
<span slot="suffix">/ 元 </span>
</el-input>
方法二:
<el-input v-model="sjje" class="money sjje" @input="inputChange">
<span slot="suffix">/ 元 </span>
</el-input>
inputChange(val) {
this.sjje = this.sjje.replace(/[^0-9.]/g, '')
}
2、form表单输入框
<el-form ref="userform" rules="rules" :model="form" label-width="110px">
<el-row>
<el-form-item label="年龄:" prop="age">
<el-input v-model="form.age"></el-input>
</el-form-item>
</el-row>
</el-form>
rules:{
age:[
{ required: true, message: '年龄不能为空', trigger: 'blur'},
{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
]
},
更多推荐
已为社区贡献1条内容
所有评论(0)