Skip to content

如何控制 input 输入框的输入字数?

参考答案:

一般是通过 maxlength 属性进行限制:

js
<input maxlength="5" />

另外还可以通过监听 οninput 事件,对输入值进行处理。