jQuery 验证(日期范围)

编程入门 行业动态 更新时间:2024-10-26 00:30:50
本文介绍了jQuery 验证(日期范围)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 jQuery 验证插件,想知道是否有办法验证输入字段的日期是否为 yyyy-mm-dd 之类的日期,并且该日期介于 2010 年 11 月 29 日至 2010 年 12 月 15 日之间

我对 jQuery 很陌生,所以如果有答案,请尽可能地把答案弄糊涂,这样我就可以通过它.非常感谢任何/所有建议

解决方案

如果你想要一个可重用的函数,你可以扩展 Emily 和 lonesomeday 的答案以允许提供参数:

$.validator.addMethod('daterange', function(value, element, arg) {//和上面一样var startDate = Date.parse(arg[0]),endDate = Date.parse(arg[1]),输入日期 = Date.parse(值);//和下面一样}, $.validator.format("请指定一个介于 {0} 和 {1} 之间的日期."))

查看来源以 jQuery 验证 range 方法为例.p>

Im using the jQuery validate plugin and was wondering if there was a way to validate if the date entered into a field was a date like yyyy-mm-dd AND the the date falls between Nov 29 2010 - Dec 15 2010

Im pretty new to jQuery so if there is an answer please dumb up the answer as much as possible so i can get through it. Thanks a lot for any/all suggestions

解决方案

If you want a reusable function, you might extend Emily and lonesomeday's answers to allow an argument to be provided:

$.validator.addMethod('daterange', function(value, element, arg) { // Same as above var startDate = Date.parse(arg[0]), endDate = Date.parse(arg[1]), enteredDate = Date.parse(value); // Same as below }, $.validator.format("Please specify a date between {0} and {1}."))

See the source of the jQuery validation range method for an example.

更多推荐

jQuery 验证(日期范围)

本文发布于:2023-11-16 07:34:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602272.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!