javascript DateTime函数和验证 [英] javascript DateTime function and validations
本文介绍了javascript DateTime函数和验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有3个文本框: -
1)StartDate
2)EndDate
3)MyDate
所有3个都有从日历中获取的日期值。
我想验证它们,以便MyDate应该在使用Javascript的开始日期和结束日期之间。
如果无效,那么我想显示一条消息。
怎么做?
我认为我们应该使用自定义验证控件要做到这一点,但如何实现呢?
任何指针都会有所帮助。
Hi I have 3 textboxs :-
1) StartDate
2) EndDate
3) MyDate
all the 3 of them has Date Values picked up from a Calender.
I want to validate them so that MyDate should be between the Start Date and End Date using Javascript.
If invalid, then I want to display a message.
How to do that?
I think we should be using custom validation controls to do that but how to implement that??
Any pointers will be helpful.
推荐答案
我想验证它们MyDate应该使用Javascript在开始日期和结束日期之间。
有多种方法可以做到这一点。最简单的是在onclick或page submit等任何事件上引发JS方法,在这里您可以找到三个控件,获取三个日期并进行比较。
示例:
I want to validate them so that MyDate should be between the Start Date and End Date using Javascript.
There can be various ways to do it. Simplest is to raise a JS method on any event like onclick or page submit, where you find the three controls, get the three dates and compare.
Sample:
function checkDateValues(startDateValue, endDateValue, myDateValue)
{
var sDate = new Date(startDateValue);
var eDate = new Date(endDateValue);
var mDate = new Date(myDateValue);
if(mDate > sDate && mDate < eDate)
{
// All good
return true;
}
return false;
}
这里有一些例子
http://www.javascriptbank.com/javascript/article/how-to/javascript-date-time-validating-tutorials / preview // [ ^ ]
here are some example
http://www.javascriptbank.com/javascript/article/how-to/javascript-date-time-validating-tutorials/preview//[^]
这篇关于javascript DateTime函数和验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文