如何使用 jQuery 限制输入到输入文本元素中的文本?

发布于 2024-09-09 08:56:02 字数 268 浏览 2 评论 0原文

我有一个输入文本元素用作具有自定义日期格式的 jQuery UI 日期选择器。日期格式允许输入月份,如 JAN、FEB 等,因此受约束的输入允许所有字符通过。请参阅此问题

如何限制输入的文本以匹配我的日期格式“dd-M-yy”?

有没有办法使用 jQuery 使输入文本元素的行为类似于屏蔽的编辑文本框?

I have an input text element being used as a jQuery UI datepicker with a custom date format. The date format allows months to be entered in as JAN, FEB, etc and so the constrained input allows all characters to go through. See this question.

How can I restrict the text entered to match my date format "dd-M-yy"?

Is there a way to use jQuery to make the input text element behave like a masked edit text box?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

命硬 2024-09-16 08:56:02

我建议使用 jQuery MaskedInput 插件,假设您的输入是固定宽度的。

I'd recommend using the jQuery MaskedInput plugin, assuming your input is fixed-width.

红衣飘飘貌似仙 2024-09-16 08:56:02

这有点脏,但也许你可以使用 http://www. zurb.com/playground/jquery-text-change-custom-event 创建您自己的过滤器?

请注意,这个插件并不肮脏,它看起来很棒,但它可能不适合这颗钉子。

It's a bit dirty, but maybe you can use http://www.zurb.com/playground/jquery-text-change-custom-event to create your own filter?

The plugin isn't dirty mind you, it looks great, but it might be the wrong hammer for this nail.

甜心 2024-09-16 08:56:02

如果您使用的是 jquery 日期选择器
您已经在插件中内置了对此的支持,

您可以在日期选择器中指定“constrainInput”选项
它是一个布尔值,只需将其设置为 true 即可。并 avcorse 指定您的日期格式。

http://docs.jquery.com/UI/Datepicker#option-constrainInput

if you are using a jquery date picker
you have built in support for this allready inside the plugin

you can specify the "constrainInput" option inside the datepicker
its a boolean just set it to true. and avcorse sepcify your date format.

http://docs.jquery.com/UI/Datepicker#option-constrainInput

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文