其中function addDate()是从网上copy来的:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function testAddDate(){
var usedate = document.all("doss_card.usedate").value;
var work_year = document.all("doss_card.work_year").value;
var tempArry=usedate.split('-');
var date=new Date(tempArry[0],tempArry[1]-1);
var newdate = addDate(6,work_year,date);
var limtyear=newdate.getYear() +'-' + (newdate.getMonth()+1);
document.all("doss_card.limit_month").value = limtyear;
}
function culEndDate(){
var inputDate=document.all("rep_month_plan.start_date").value;
var datePartArray=inputDate.split('-');
//本月开始的第一天
var curFirstDay=new Date(datePartArray[0],datePartArray[1]-1);
//下月开始的第一天
var nextFirstDay=addDate('5','1',curFirstDay);
//下下月开始的第一天
var nnextFirstDay=addDate('5','2',curFirstDay);
//本月最后一天
var curEndDay= new Date(nextFirstDay.getTime()-1);
//下月最后一天
var nextEndDay= new Date(nnextFirstDay.getTime()-1);
alert(nextEndDay);
document.all("rep_month_plan.curEnddate").value=curEndDay.getYear() +'-' + (curEndDay.getMonth()+1) + '-' +curEndDay.getDate();
document.all("rep_month_plan.nextEnddate").value=nextEndDay.getYear() +'-' + (nextEndDay.getMonth()+1) + '-' +nextEndDay.getDate();
}
function addDate(type,NumDay,vdate){
var date=new Date(vdate);
type = parseInt(type) //类型
var lIntval = parseInt(NumDay)//间隔
switch(type){
case 6 ://年
date.setYear(date.getYear() + lIntval)
break;
case 7 ://季度
date.setMonth(date.getMonth() + (lIntval * 3) )
break;
case 5 ://月
date.setMonth(date.getMonth() + lIntval)
break;
case 4 ://天
date.setDate(date.getDate() + lIntval)
break
case 3 ://时
date.setHours(date.getHours() + lIntval)
break
case 2 ://分
date.setMinutes(date.getMinutes() + lIntval)
break
case 1 ://秒
date.setSeconds(date.getSeconds() + lIntval)
break;
default:
}
return date;
//return date.getYear() +'-' + (date.getMonth()+1) + '-' +date.getDate()+ ' '+ date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()
}
//-->
</SCRIPT>
</HEAD>
<FORM METHOD=POST ACTION="">
doss_card.usedate:<INPUT TYPE="text" NAME="doss_card.usedate" value='2007-06'><BR>
doss_card.work_year:<INPUT TYPE="text" NAME="doss_card.work_year" value='6'><BR>
doss_card.limit_month:<INPUT TYPE="text" NAME="doss_card.limit_month"><BR>
<INPUT TYPE="button" value='计算日期相加' onclick='testAddDate()'>
<hr>
当前日期:<INPUT TYPE="text" NAME="rep_month_plan.start_date" value='2007-06-12'><BR>
当月末日期:<INPUT TYPE="text" NAME="rep_month_plan.curEnddate"><BR>
下月末日期:<INPUT TYPE="text" NAME="rep_month_plan.nextEnddate" ><BR>
<INPUT TYPE="button" value='计算月末日期' onclick='culEndDate()'>
</FORM>
<BODY>
</BODY>
</HTML>