我正在使用javascript日期,并且如果我显示2day日期以前的日期和一个月的即将到来的日期应该被禁用,任何人都可以帮我吗 [英] I am usong javascript date and whn i display 2day date previous dates and upcoming dates for one month should be disabled can any one help me

查看:92
本文介绍了我正在使用javascript日期,并且如果我显示2day日期以前的日期和一个月的即将到来的日期应该被禁用,任何人都可以帮我吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我正在使用javascript日期,并且如果我显示2天日期以前的日期和一个月的未来日期应该被禁用,谁能帮我吗

Hi I am usong javascript date and whn i display 2day date previous dates and upcoming dates for one month should be disabled can any one help me

推荐答案

/* _________________________________________________________________________
文件名:date.js
创建于:12/9/2003
作者:Sharath Chandra
修改日期:2003年12月9日
说明:该js用于日期验证
合著者:
___________________________________________________________________________ */

函数getDateDifference(journeyDate1,currentDate1)
{

travelDate =新日期(journeyDate1.toGMTString());
currentDate =新日期(currentDate1.toGMTString());

Yearjn = takeYear(journeyDate);
Monthjn = travelDate.getMonth();
Dayjn = travelDate.getDate();
Modjn =(Date.UTC(Yearjn,Monthjn,Dayjn,0,0,0))/86400000;
Yearcur = takeYear(currentDate);
Monthcur = currentDate.getMonth();
Daycur = currentDate.getDate();
Modcur =(Date.UTC(Yearcur,Monthcur,Daycur,0,0,0))/86400000;
daysago = Math.floor(Modjn-Modcur);
返回日前;
}

函数takeYear(theDate)
{
x = theDate.getYear();
var y = x%100;
y + =(y< 38)吗? 2000:1900;
返回y;
}

函数isValidJourneyDate(formName,currentDate,strDate)
{
var t;
if(document.forms [formName] .quota.value =="CK")
t =''tatkal'';
其他
t =''正常'';
var z =''eticket'';
if(document.forms [formName] .ticketType.value =="iticket")
{
z =''iticket'';
}
diff = getDateDifference(new Date(document.forms [formName] .year [document.forms [formName] .year.selectedIndex] .value,parseInt(document.forms [formName] .month [document.forms [formName] .month. selectedIndex] .value)-1,document.forms [formName] .day [document.forms [formName] .day.selectedIndex] .value),currentDate);
if(parseInt(diff)< 3&& z ==''iticket'')
{
alert(请检查旅程日期.\ nI-机票不允许Tatkal票.\ n对于普通I-门票,旅行日期应为今天后3天.");
返回false;
}
否则if(parseInt(diff)< 0&& z ==''eticket'')
{
alert(请检查旅程的日期... \ n旅程的日期应从今天开始");
返回false;
}
/* DT */
if(document.forms [formName] .userType.value!= 0&& t ==''tatkal''&&(strDate == 8))
{
alert(不允许代理商在08:00 AM到09:00 AM之间预订Tatkal票");

返回false;
}
/* DT */
if(parseInt(diff)== 1&& t ==''tatkal''&& z ==''iticket'')
{
if(strDate< 8)
{
alert(请检查旅程日期.\ n I-Ticket不允许使用Tatkal票.\ n对于普通I-Ticket,旅行日期应为今天之后的3天.");
返回false;//取消注释
}
}
if(parseInt(diff)== 1&& t ==''tatkal''&& z ==''ticket'')
{
if(strDate< 8)
{
alert(对不起,您只能在8:00小时后预订电子票");
返回false;//取消注释
}
}
if(parseInt(diff)> 1&& t ==''tatkal''&& z ==''iticket'')
{
alert(请检查旅程日期.\ n I-Ticket不允许使用Tatkal票.\ n对于普通I-Ticket,旅行日期应为今天之后的3天.");
返回false;
}
if(parseInt(diff)> 1&& t ==''tatkal''&& z ==''ticket'')
{
alert(请检查旅程的日期... \ n旅程的日期应在距今天两天之内,例如,您可以在第一天预订直到第三天的旅程.");
返回false;
}
/* DT *//*开始*/
if(document.forms [formName] .userType.value!= 0&& parseInt(diff)> = 90&&(strDate == 8))
{
alert(对不起的特工,您只能在开放日的09:00后预订票");

返回false;
}
/* DT *//*结束*/

if(parseInt(diff)> 0)
{
alert(请检查旅程日期..\ n可以提前90天预订火车,\ n尊重出发站(旅程日期不计算在内)");
返回false;
}
if(parseInt(diff)== 0)
{
if(strDate< 8)
{
alert(对不起,您只能在开放日8:00 Hrs之后预定票务");
返回false;//取消注释
}
}
返回true;
}

//StrutsTic20/19-02-2004/Sharath/mod开始
函数isValidJourneyDates(formName,currentDate,name)
{
diff = getDateDifference(new Date(document.forms [formName] .year [document.forms [formName] .year.selectedIndex] .value,parseInt(document.forms [formName] .month [document.forms [formName] .month. selectedIndex] .value)-1,document.forms [formName] .day [document.forms [formName] .day.selectedIndex] .value),currentDate);
if(parseInt(diff)< 0)
{
alert(请检查您输入的日期");
返回false;
}
if(parseInt(diff)> 0)
{
alert(name +可用于当前日期的后90天");
返回false;
}
返回true;
}

函数isFeb(month,day)
{
if(month == 1&& day> 29)
{
alert(二月不包含1天");
返回true;
}
返回false;
}
//StrutsTic20/19-02-2004/Sharath/mod结束


//IRCTC_WishList8/11-MAR-2004/SUNIL/MOD BEGINS
函数isValidJourneyDateFromFailedPayments(formName,currentDate,journeyDate,type_t)
{
diff = getDateDifference(journeyDate,currentDate);

if(parseInt(diff)< 3&& type_t =="iticket")//MALAY TATKAL MOD 23 DEC 05
{
alert(请检查旅程的日期..\ n旅程的日期应该是今天之后的三天");
返回false;
}
if(parseInt(diff)< 0&& type_t =="eticket")//MALAY TATKAL MOD 23 DEC 05
{
alert(请检查旅程的日期..\ n旅程的日期不应该是今天的前一天");
返回false;
}
if(parseInt(diff)> 0)
{
alert(请检查旅程日期..n今天允许90天预订");
返回false;
}


返回true;
}
//IRCTC_WishList8/11-MAR-2004/SUNIL/MOD ENDS
//StrutsTic33/13-04-2004/Sharath/Mod Begins
//现在无需验证此功能,因为现在只有用于选择日期的日历

函数isValidDate(formName)
{
var day = document.forms [formName] .day [document.forms [formName] .day.selectedIndex] .value;
var month = document.forms [formName] .month [document.forms [formName] .month.selectedIndex] .value;
var year = document.forms [formName] .year [document.forms [formName] .year.selectedIndex] .value;
if(checkYear(year)== 1)
{
if(month =="1"&& day> 29)
{
alert(二月不包含1天");
返回false;
}
}
if(checkYear(year)== 0)
{
if(month =="1"&& day> 28)
{
alert("2月仅包含18天");
返回false;
}
}
if(month =="4"&& day> 1)
{
alert(四月不包含31天");
返回false;
}
if(month =="6"&& day> 1)
{
alert(六月月份不包含31天");
返回false;
}
if(month =="9"&& day> 1)
{
alert(九月份不包含31天");
返回false;
}
if(month =="11"&& day> 1)
{
alert(十一月不包含31天");
返回false;
}
返回true;
}
函数checkYear(year){
返回((((年%4 == 0)&&(年%100!= 0))||(年%400 == 0))吗? 1:0;
}
//StrutsTic33/13-04-2004/Sharath/Mod Ends
/*_________________________________________________________________________
File Name : date.js
Created on : 12/9/2003
Author : Sharath Chandra
Modified on : 12/9/2003
Description : This js is for date Validation
Co-Author :
___________________________________________________________________________*/

function getDateDifference(journeyDate1,currentDate1)
{

journeyDate = new Date(journeyDate1.toGMTString());
currentDate= new Date(currentDate1.toGMTString());

Yearjn = takeYear(journeyDate);
Monthjn = journeyDate.getMonth();
Dayjn = journeyDate.getDate();
Modjn = (Date.UTC(Yearjn,Monthjn,Dayjn,0,0,0))/86400000;
Yearcur = takeYear(currentDate);
Monthcur = currentDate.getMonth();
Daycur = currentDate.getDate();
Modcur = (Date.UTC(Yearcur,Monthcur,Daycur,0,0,0))/86400000;
daysago =Math.floor( Modjn - Modcur);
return daysago;
}

function takeYear(theDate)
{
x = theDate.getYear();
var y = x % 100;
y += (y < 38) ? 2000 : 1900;
return y;
}

function isValidJourneyDate(formName,currentDate,strDate)
{
var t;
if(document.forms[formName].quota.value=="CK")
t=''tatkal'';
else
t=''normal'';
var z=''eticket'';
if(document.forms[formName].ticketType.value=="iticket")
{
z=''iticket'';
}
diff=getDateDifference(new Date(document.forms[formName].year[document.forms[formName].year.selectedIndex].value,parseInt(document.forms[formName].month[document.forms[formName].month.selectedIndex].value)-1,document.forms[formName].day[document.forms[formName].day.selectedIndex].value),currentDate);
if(parseInt(diff)<3 && z==''iticket'')
{
alert(" Please check the journey Date.\nTatkal Ticket is not allowed in I-Ticket. \nThe Date of Journey should be 3 days after today for normal I-Ticket. ");
return false;
}
else if(parseInt(diff)<0 && z==''eticket'')
{
alert(" Please Check The Journey Date... \n The Date Of Journey Should Be From Today ");
return false;
}
/*DT*/
if(document.forms[formName].userType.value!=0 && t==''tatkal'' && (strDate==8))
{
alert(" Agents are not allowed to book Tatkal tickets between 08:00 AM to 09:00 AM");

return false;
}
/*DT*/
if(parseInt(diff)==1 && t==''tatkal'' && z==''iticket'')
{
if(strDate<8)
{
alert(" Please check the journey Date.\n Tatkal Ticket is not allowed in I-Ticket. \n The Date of Journey should be 3 days after today for normal I-Ticket.");
return false;//uncomment it
}
}
if(parseInt(diff)==1 && t==''tatkal'' && z==''eticket'')
{
if(strDate<8)
{
alert("Sorry You can book eTicket only after 8:00 Hrs");
return false;//uncomment it
}
}
if(parseInt(diff)>1 && t==''tatkal'' && z==''iticket'')
{
alert(" Please check the journey Date.\n Tatkal Ticket is not allowed in I-Ticket. \n The Date of Journey should be 3 days after today for normal I-Ticket.");
return false;
}
if(parseInt(diff)>1 && t==''tatkal'' && z==''eticket'')
{
alert(" Please Check The Journey Date... \n The Date Of Journey Should Be Within Two Days From Today eg., on 1st you can book for journey upto 3rd. ");
return false;
}
/*DT*//*start*/
if(document.forms[formName].userType.value!=0 && parseInt(diff)>=90 && (strDate==8))
{
alert(" Sorry Agent ,You can book Ticket only after 09:00 Hrs for opening day");

return false;
}
/*DT*//*end*/

if(parseInt(diff)>0)
{
alert(" Please Check The Journey Date.. \n Reservation is permitted for 90 days in advance with \nrespect to train starting station(journey date not to be counted)");
return false;
}
if(parseInt(diff)==0)
{
if(strDate<8)
{
alert("Sorry You can book Ticket only after 8:00 Hrs for opening day");
return false;//uncomment it
}
}
return true;
}

//StrutsTic20/19-02-2004/Sharath/mod begins
function isValidJourneyDates(formName,currentDate,name)
{
diff=getDateDifference(new Date(document.forms[formName].year[document.forms[formName].year.selectedIndex].value,parseInt(document.forms[formName].month[document.forms[formName].month.selectedIndex].value)-1,document.forms[formName].day[document.forms[formName].day.selectedIndex].value),currentDate);
if(parseInt(diff)<0)
{
alert("Please Check The Date You Have Entered");
return false;
}
if(parseInt(diff)>0)
{
alert(name+" is Available for Next 90 Days from the Current Day");
return false;
}
return true;
}

function isFeb(month,day)
{
if(month==1 && day>29)
{
alert("The Feb month does not contain 1 days");
return true;
}
return false;
}
//StrutsTic20/19-02-2004/Sharath/mod ends


//IRCTC_WishList8/11-MAR-2004/SUNIL/MOD BEGINS
function isValidJourneyDateFromFailedPayments(formName,currentDate,journeyDate,type_t)
{
diff=getDateDifference(journeyDate,currentDate);

if(parseInt(diff)<3 && type_t=="iticket")//MALAY TATKAL MOD 23 DEC 05
{
alert(" Please Check The Journey Date.. \n The Date Of Journey Should Be 3 Days After Today ");
return false;
}
if(parseInt(diff)<0 && type_t=="eticket")//MALAY TATKAL MOD 23 DEC 05
{
alert(" Please Check The Journey Date.. \n The Date Of Journey Should Not Be The Day Before Today ");
return false;
}
if(parseInt(diff)>0)
{
alert(" Please Check The Journey Date.. \n Reservation Is Permitted For 90 Days Form Today ");
return false;
}


return true;
}
//IRCTC_WishList8/11-MAR-2004/SUNIL/MOD ENDS
//StrutsTic33/ 13-04-2004/ Sharath/ Mod Begins
//Now No need To Validate This Functio Because Now we have only Calendar For selecteing date

function isValidDate(formName)
{
var day = document.forms[formName].day[document.forms[formName].day.selectedIndex].value;
var month = document.forms[formName].month[document.forms[formName].month.selectedIndex].value;
var year = document.forms[formName].year[document.forms[formName].year.selectedIndex].value;
if(checkYear(year)==1)
{
if(month =="1" && day>29)
{
alert("The Feb month does not contain 1 days");
return false;
}
}
if(checkYear(year)==0)
{
if(month =="1" && day>28)
{
alert("The Feb month contain Only 18 days");
return false;
}
}
if(month =="4" && day>1)
{
alert("The April month does not contain 31 days");
return false;
}
if(month =="6" && day>1)
{
alert("The June month does not contain 31 days");
return false;
}
if(month =="9" && day>1)
{
alert("The September month does not contain 31 days");
return false;
}
if(month =="11" && day>1)
{
alert("The November month does not contain 31 days");
return false;
}
return true;
}
function checkYear(year) {
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}
//StrutsTic33/ 13-04-2004/ Sharath/ Mod Ends


这篇关于我正在使用javascript日期,并且如果我显示2day日期以前的日期和一个月的即将到来的日期应该被禁用,任何人都可以帮我吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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