<表格名稱=“表格”>
<表>
<TR>
<TD>當前日期:</TD>
<TD><input type="text" name="u" value="2009-01-01"></TD>
</TR>
<TR>
<TD>要加的天數:</TD>
<TD><INPUT TYPE="text" name="entry" id="d" VALUE="" onkeyup="calculate('d')"></TD>
</TR>
<TR>
<TD>要加的周數:</TD>
<TD><INPUT TYPE="text" name="entry" id="w" VALUE="" onkeyup="calculate('w')"></TD>
</TR>
<TR>
<TD>要加的月數:</TD>
<TD><INPUT TYPE="text" name="entry" id="m" VALUE="" onkeyup="calculate('m')"></TD>
</TR>
<TR>
<TD>要加的年數:</TD>
<TD><INPUT TYPE="text" name="entry" id="y" VALUE="" onkeyup="calculate('y')"></TD>
</TR>
<TR>
<TD>結果:</TD>
<TD><輸入名稱=“兩次”></TD>
</TR>
<!--<TR>
<TD>要新增的日期2:</TD>
<TD><input type="text" name="u" value="2009/01/01"></TD>
</TR>
<TR>
<TD>結果2:</TD>
<TD><輸入名稱=“兩次”></TD>
</TR>-->
</表>
</形式>
<腳本語言=“JavaScript”>
函數 DateAdd(strInterval, NumDay, dtDate) {
var dtTmp = 新日期(dtDate);
if (isNaN(dtTmp)) dtTmp = new Date();
開關(strInterval){
案例“s”:
dtTmp = new Date(Date.parse(dtTmp) + (1000 * parseInt(NumDay)));
休息;
情況“n”:
dtTmp = new Date(Date.parse(dtTmp) + (60000 * parseInt(NumDay)));
休息;
情況“h”:
dtTmp = new Date(Date.parse(dtTmp) + (3600000 * parseInt(NumDay)));
休息;
情況“d”:
dtTmp = new Date(Date.parse(dtTmp) + (86400000 * parseInt(NumDay)));
休息;
案例“w”:
dtTmp = new Date(Date.parse(dtTmp) + ((86400000 * 7) * parseInt(NumDay)));
休息;
案例“m”:
dtTmp = new Date(dtTmp.getFullYear(), (dtTmp.getMonth())+parseInt(NumDay), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
休息;
情況“y”:
//警報(dtTmp.getFullYear());
dtTmp = new Date(dtTmp.getFullYear()+parseInt(NumDay), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
//警報(dtTmp);
休息;
}
var mStr=new String(dtTmp.getMonth()+1);
var dStr=new String(dtTmp.getDate());
if (mStr.length==1){
mStr=“0”+mStr;
}
if (dStr.length==1){
dStr=“0”+dStr;
}
返回 dtTmp.getFullYear()+"-"+mStr+"-"+dStr;
}
</腳本>
<script language="JavaScript">
函數計算(類型)
{
var Entry = document.getElementById(type).value;//自己判斷是否合法
var uValue=document.form.u.value;
uValue=uValue.replace("-","/").replace("-","/");
//警報(uValue);
document.form.twice.value = DateAdd(型,條目,uValue);
}
</腳本>