19

[Vue] el-input特性记录2-最大值、最小值

 3 years ago
source link: https://segmentfault.com/a/1190000040044918
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[Vue] el-input特性记录2-最大值、最小值

发布于 33 分钟前

el-input输入值设置最大值、最小值问题。

如果使用max、min属性,则必须同时加上与type="number"。
设置type="number"样式,输入框尾部会出现一个上下箭头,min和max只能控制用箭头输入的最大值最小值,对键盘打字输入是限制不住的。

如果需要限制input输入的值,最实用的做法是给input绑定一个change事件,在change事件中用正则判断。这里会涉及到一个type=”number”同时正则判定,对"e"失效的问题。(要看怎么理解失效)

设置了type=”number”,同时change事件的正则是判定只能输入正数,如果不是正数则清空。
此时输入”a”,”b”,”c”,”d”,或者“-2”的时候会进入正则,input框直接被清空。

但是输入“e”却能够输入。这是因为自然常数e=2.71828,这个e会被type=”number”判定为合规,不会进入正则。因此不想出现e的话,就不要设置type=”number”。

搬运自自己的语雀
https://www.yuque.com/diracke...


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK