el-input中oninput限制只能输入正整数
时间: 2023-10-17 08:25:26 浏览: 196
在ElementUI的el-input组件中,可以通过使用oninput事件和正则表达式来限制只能输入正整数。可以使用以下代码实现:
```html
<el-input v-model.number="value" oninput="value=value.replace(/[^\d]/g,'')"></el-input>
```
在这个代码中,通过使用oninput事件监听输入框的输入,然后使用正则表达式`/[^\d]/g`将非数字字符替换为空字符串,从而实现限制只能输入正整数的功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Vue与Element el-input 限制为正整数输入](https://blog.csdn.net/News777/article/details/126462202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [el-input输入框限制输入0-100正整数](https://blog.csdn.net/weixin_45304198/article/details/129789996)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文