jQuery函数将日期与当前日期进行比较 [英] jQuery function to compare date with current date
本文介绍了jQuery函数将日期与当前日期进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过在单独的文本框中输入日期,从下拉列表中选择年份并在文本框中输入年份来输入表格中的出生日期。现在我想检查输入的日期不能大于jquery中的当前日期。请帮忙怎么样?
i am entering date of birth in form by entering date in separate text box ,selecting year from drop down and entering year in text box. Now i want to check that entered date must not be greater that current date in jquery. Please help how?
var CurrentMonth = date.getDate() + '/' + date.getMonth() + '/' + date.getFullYear();
var SelectedDate = $('[id$=spDate]').val() + '/' + $('[id$=drpMonth]').val() + '/' + $('[id$=txtYear]').val();
if (CurrentDate > SelectedDate) {
return false;
}
推荐答案
如果您的输入值是整数,你可以构建一个 日期
使用它们的实例:
Provided that your input values are integers, you can construct a Date
instance using them:
var CurrentDate = new Date();
var SelectedDate = new Date(
$('[id$=txtYear]').val(),
$('[id$=drpMonth]').val(),
$('[id$=spDate]').val()
);
//As quite rightly mentioned, January = 0, so if your inputs have the literal number for each month (1 for January) replace the line above with the following, to take a month off:
//var SelectedDate = new Date($('[id$=txtYear]').val(), $('[id$=drpMonth]').val()-1, $('[id$=spDate]').val());
if(CurrentDate > SelectedDate){
//CurrentDate is more than SelectedDate
}
else{
//SelectedDate is more than CurrentDate
}
这篇关于jQuery函数将日期与当前日期进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文