我可以为经典 ASP 创建带有日期分隔符的日期输入控件吗
我在经典 ASP 应用程序中使用日历控件来输入日期。但日历控件不适合键盘,并且需要更多时间输入数据。所以后来我添加了一个带有日期验证的简单文本框。效果很好。但是,用户还需要输入日期分隔符。我希望放置一个带有预先配置的日期格式和分隔符的日期输入字段,以便用户只需输入数字,该字段也会引起验证。
我怎样才能实现这个目标?
I was using a calendar control for entry of date in a classic-ASP application. But calendar control is not keyboard friendly and take more time for data entry. So later I added a simple text box with date validation. It works fine. However, the user need to put the date separator also. I wish to put a date entry field that comes with a pre-configured date format and separator, so that the user simply type on the numbers and the field cause a validation as well.
How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用 jQuery/javascript 来屏蔽日期文本字段。当用户输入值时,它将自动设置日期格式。还强制进行正确的验证。
例如 jQuery 插件搜索:
jquery date mask: http://digitalbush.com/projects/masked -输入插件/
Just use jQuery/javascript to mask the date text field. It will automatically format the date as the user enters the values. Also forces correct validation as it works.
for example jQuery plugins search for :
jquery date mask: http://digitalbush.com/projects/masked-input-plugin/
您始终可以放置三个带有分隔符的文本框作为文本(就像我在旧的 ASP 经典站点中所做的那样)
您需要分隔响应中的日期,然后在发布时使用
DateSerial
将其连接起来。You can always put three text boxes with the separator as text (as I do in an old ASP classic site)
You need to separate the date in the response and then join it using
DateSerial
when posted.当我们过去创建类似的东西时,我们允许用户以几种不同的方式在文本框中输入日期:
提交表单时,我们有一个简单的ASP 函数将 DDMMYYYY 转换为 DD/MM/YYYY(日期字符串必须为 8 个字符,因为假设 DD 为 2 位数字,插入分隔符,2 为 MM 等)并检查这是一个有效的日期,并且 < code>if formdate = 0 then formdate=now() 规则。
不过,您还需要在表单上添加一些 JavaScript 验证。在文本框中添加 onblur 事件来检查相同的内容 - 输入 8 位数字、有效日期或 0 - 否则提醒用户。 (如果我们今天重做的话,我会在 jQuery 中执行此操作)
如果您愿意,您可以使用 Javascript“验证”来加速数据输入,例如,如果输入的许多日期是昨天或明天允许的-1 或 +1,或者如果数据输入始终是当月但不同的一天,则允许用户仅输入数字 - 15,Javascript/jQuery 会将字符串转换为 15/03/2011。
When we've created something similar in the past we've allowed the user to enter a date into a textbox in a couple of different ways:
When the form is submitted we had a simple ASP function to convert DDMMYYYY into DD/MM/YYYY (date string must be 8 characters though because the assumption was 2 digits for DD, insert the separator, 2 for MM, etc.) and check this was a valid date, and an
if formdate = 0 then formdate=now()
rule.You need to add some JavaScript validation on the form too though. On the textbox add an onblur event to check for the same things - either 8 digits entered, or a valid date, or a 0 - otherwise alert the user. (I would do this in jQuery if we were redoing it today)
You can get quite helpful with the Javascript "validation" to speed up data-entry if you wanted to, for example if a lot of dates being entered are yesterday or tomorrow allow a -1 or +1, or if data entry is always for the current month but a different day, allow the user to just enter a number - 15 and the Javascript/jQuery converts the string to 15/03/2011.
使用 HTML 5...textMode="日期"
With HTML 5...textMode="Date"