<nombre del formulario="formulario">
<TABLA>
<TR>
<TD>现在的日期:</TD>
<TD><tipo de entrada="texto" nombre="u" valor="2009-01-01"></TD>
</TR>
<TR>
<TD>要加的天数:</TD>
<TD><INPUT TYPE="texto" nombre="entrada" id="d" VALUE="" onkeyup="calcular('d')"></TD>
</TR>
<TR>
<TD>要加的周数:</TD>
<TD><INPUT TYPE="texto" nombre="entrada" id="w" VALUE="" onkeyup="calcular('w')"></TD>
</TR>
<TR>
<TD>要加的月数:</TD>
<TD><INPUT TYPE="texto" nombre="entrada" id="m" VALUE="" onkeyup="calcular('m')"></TD>
</TR>
<TR>
<TD>要加的年数:</TD>
<TD><INPUT TYPE="texto" nombre="entrada" id="y" VALUE="" onkeyup="calcular('y')"></TD>
</TR>
<TR>
<TD>结果:</TD>
<TD><nombre de entrada="dos veces"></TD>
</TR>
<!--<TR>
<TD>要加的日期2:</TD>
<TD><tipo de entrada="texto" nombre="u" valor="2009/01/01"></TD>
</TR>
<TR>
<TD>结果2:</TD>
<TD><nombre de entrada="dos veces"></TD>
</TR>-->
</TABLA>
</formulario>
<lenguaje de escritura="JavaScript">
función AgregarFecha(strInterval, NumDay, dtDate) {
var dtTmp = nueva Fecha(dtDate);
if (isNaN(dtTmp)) dtTmp = nueva fecha();
cambiar (strInterval) {
caso "s":
dtTmp = nueva Fecha(Date.parse(dtTmp) + (1000 * parseInt(NumDay)));
romper;
caso "n":
dtTmp = nueva Fecha(Date.parse(dtTmp) + (60000 * parseInt(NumDay)));
romper;
caso "h":
dtTmp = nueva Fecha(Date.parse(dtTmp) + (3600000 * parseInt(NumDay)));
romper;
caso "d":
dtTmp = nueva Fecha(Date.parse(dtTmp) + (86400000 * parseInt(NumDay)));
romper;
caso "w":
dtTmp = nueva Fecha(Date.parse(dtTmp) + ((86400000 * 7) * parseInt(NumDay)));
romper;
caso "m":
dtTmp = nueva Fecha(dtTmp.getFullYear(), (dtTmp.getMonth())+parseInt(NumDay), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
romper;
caso "y":
//alerta(dtTmp.getFullYear());
dtTmp = nueva Fecha(dtTmp.getFullYear()+parseInt(NumDay), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
//alerta(dtTmp);
romper;
}
var mStr=new String(dtTmp.getMonth()+1);
var dStr=new String(dtTmp.getDate());
si (mStr.length==1){
mStr="0"+mStr;
}
si (dStr.length==1){
dStr="0"+dStr;
}
return dtTmp.getFullYear()+"-"+mStr+"-"+dStr;
}
</script>
<script language="JavaScript">
función calcular(tipo)
{
entrada var = document.getElementById(tipo).valor;//自己判断是否合法
var uValue=document.form.u.value;
uValue=uValue.replace("-","/").replace("-","/");
//alerta(uValue);
document.form.twice.value = DateAdd(tipo,entrada,uValue);
}
</script>