使用 jquery 创建文本输入组合?
我想知道 jquery 是否可以使文本字段只接受 3 个字母和 4 个数字的组合(例如 ABC1234) - 按这个顺序?
i was wondering whether it was possible for jquery to make a text field only accept a combination of 3 letters and 4 numbers (eg ABC1234) - in that order?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://jsfiddle.net/MEvj3/
这是一种方法的简化示例。
http://jsfiddle.net/MEvj3/
Here's a simplified example of one way.
如果您创建了一个带有 maxlength...
...那么您可以检查它的长度和 jQuery 的
e.which
:请注意,有一些陷阱:
,代码相当草率。它只是应该让人们理解基本的想法;您可能需要对其进行调整才能获得真正适合您的项目的东西。
If you created an input with a maxlength...
...then you could just check it's length and jQuery's
e.which
:Note that there are some gotchas:
Honestly, the code is pretty sloppy. It's just supposed to get the basic idea across; you'll probably have to tweak it to get something that really works for your project.