jQuery屏蔽输入 - 格式日期为m / d / yyyy或m / dd / yyyy或mm / dd / yyyy或mm / d / yyyy [英] jQuery masked input - format date as m/d/yyyy or m/dd/yyyy or mm/dd/yyyy or mm/d/yyyy

查看:241
本文介绍了jQuery屏蔽输入 - 格式日期为m / d / yyyy或m / dd / yyyy或mm / dd / yyyy或mm / d / yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用这里找到的jQuery masked input插件 http://digitalbush.com/ projects / masked-input-plugin / 来格式化日期。

我从数据库中提取数据以填充页面加载时的日期字段。如果不正确,用户将能够更改日期。



我希望人们能够在一个月份和一天中只输入一个数字,而不必在一位数字之前输入0。我希望他们能够输入6/13/2010而不是06/13/2010。尽管如此,数据库中的数据可能没有0。



我知道,是可选的,但我希望在开始或中间的字符是可选的。



谢谢!

解决方案

最近我有一个类似的要求,我唯一能找到的东西并不需要我在调整插件上做很多工作,就是使用这个修改的日期掩码插件是基于你提到的。到目前为止,这似乎在做这项工作。



如果你想测试一下,

这个修改过的日期掩码的基本实现如下所示:


$ b $

  $('#yourInputBoxHere')。mask(99/99/9999,{placeholder:'MM / DD / YYYY'}); 

我还没有用日期的单个数字尝试过,但如果我要这样做, 'd只是改变上面的表达式为:

  $('#yourInputBoxHere')。mask(9/9/9999 ,{占位符:'M / D / YYYY'}); 

我希望这有助于您。


I want to use the jQuery masked input plugin found here http://digitalbush.com/projects/masked-input-plugin/ to format the date.

I am pulling data from a database to populate the date field when the page loads. The user will then be able to change the date if it is incorrect.

I want people to be able to enter just one number for the month and day instead of having to enter a 0 before a single-digit number. I want them to be able to type 6/13/2010 instead of 06/13/2010. The data from the database might not have 0's in front, though.

I know that anything listed after a ? is optional, but I want characters at the beginning or middle to be optional.

Thanks!

解决方案

I had a similar requirement recently, and the only thing I could find that didn't require me to do a lot of work on tweaking the plugin was to use this modified date masking plugin that is based on the one you mentioned. It seems to be doing the job so far.

If you want to test it out, head to this page.

The basic implementation we've used with this modified date masker is as follows:

$('#yourInputBoxHere').mask("99/99/9999", {placeholder: 'MM/DD/YYYY' });

I haven't tried it with single digits for dates, but if I were to do it, I'd just change the above expression to this:

$('#yourInputBoxHere').mask("9/9/9999", {placeholder: 'M/D/YYYY' });

I hope this helps.

这篇关于jQuery屏蔽输入 - 格式日期为m / d / yyyy或m / dd / yyyy或mm / dd / yyyy或mm / d / yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆