假设我有这样的输入:

$('#phone').mask("?99999", { placeholder: "" });


如果键入'12345',然后将光标置于34之间,然后按1,则文本将类似于:
'12314'

我想要类似maxlength的行为,当达到限制时,该行为可以防止出现任何其他字符,因此如果maxlength = 5,文本将保持为'12345'。

这是插件:http://digitalbush.com/projects/masked-input-plugin/

最佳答案

编辑

首先,使用在How do I keep existing values from shifting to the right when entering keypresses into a jQuery Masked Input?处找到的解决方案,以避免掩码插件的行为使按键上的字符向右移动。

然后,将maxlength设置为输入的属性

<input type="text" id="phone" maxlength="5">


这将限制输入长度。

10-07 19:37
查看更多