<nom du formulaire="formulaire">
<TABLE>
<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><nom d'entrée="deux fois"></TD>
</TR>
<!--<TR>
<TD>要加的日期2:</TD>
<TD><input type="text" name="u" value="2009/01/01"></TD>
</TR>
<TR>
<TD>结果2:</TD>
<TD><nom d'entrée="deux fois"></TD>
</TR>-->
</TABLE>
</form>
<langage de script="JavaScript">
fonction DateAdd (strInterval, NumDay, dtDate) {
var dtTmp = nouvelle Date(dtDate);
if (isNaN(dtTmp)) dtTmp = new Date();
commutateur (strInterval) {
cas "s":
dtTmp = new Date(Date.parse(dtTmp) + (1000 * parseInt(NumDay)));
casser;
cas "n":
dtTmp = new Date(Date.parse(dtTmp) + (60000 * parseInt(NumDay)));
casser;
cas "h":
dtTmp = new Date(Date.parse(dtTmp) + (3600000 * parseInt(NumDay)));
casser;
cas "d":
dtTmp = new Date(Date.parse(dtTmp) + (86400000 * parseInt(NumDay)));
casser;
cas "w":
dtTmp = new Date(Date.parse(dtTmp) + ((86400000 * 7) * parseInt(NumDay)));
casser;
cas "m":
dtTmp = new Date(dtTmp.getFullYear(), (dtTmp.getMonth())+parseInt(NumDay), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
casser;
cas "y":
//alerte(dtTmp.getFullYear());
dtTmp = new Date(dtTmp.getFullYear()+parseInt(NumDay), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
//alerte(dtTmp);
casser;
}
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 langage="JavaScript">
fonction calculer(type)
{
var Entry = document.getElementById(type).value;//自己判断是否合法
var uValue=document.form.u.value;
uValue=uValue.replace("-","/").replace("-","/");
//alerte(uValue);
document.form.twice.value = DateAdd(type,entry,uValue);
}
</script>