<nama formulir="form">
<TABEL>
<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><input nama="dua kali"></TD>
</TR>
<!--<TR>
<TD>要加的日期2:</TD>
<TD><input type="text" name="u" value="2009/01/01"></TD>
</TR>
<TR>
<TD>结果2:</TD>
<TD><input nama="dua kali"></TD>
</TR>-->
</TABEL>
</bentuk>
<bahasa skrip="JavaScript">
fungsi DateAdd(strInterval, NumDay, dtDate) {
var dtTmp = Tanggal baru(tanggal dt);
if (isNaN(dtTmp)) dtTmp = Tanggal baru();
beralih (strInterval) {
kasus "s":
dtTmp = Tanggal baru(Tanggal.parse(dtTmp) + (1000 * parseInt(Jumlah Hari)));
merusak;
kasus "n":
dtTmp = Tanggal baru(Tanggal.parse(dtTmp) + (60000 * parseInt(Nomor Hari)));
merusak;
kasus "h":
dtTmp = Tanggal baru(Tanggal.parse(dtTmp) + (3600000 * parseInt(Nomor Hari)));
merusak;
kasus "d":
dtTmp = Tanggal baru(Tanggal.parse(dtTmp) + (86400000 * parseInt(Nomor Hari)));
merusak;
kasus "w":
dtTmp = Tanggal baru(Tanggal.parse(dtTmp) + ((86400000 * 7) * parseInt(NumDay)));
merusak;
kasus "m":
dtTmp = Tanggal baru(dtTmp.getFullYear(), (dtTmp.getMonth())+parseInt(NumDay), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
merusak;
kasus "y":
//alert(dtTmp.getFullYear());
dtTmp = Tanggal baru(dtTmp.getFullYear()+parseInt(NumDay), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds());
//peringatan(dtTmp);
merusak;
}
var mStr=String baru(dtTmp.getMonth()+1);
var dStr=String baru(dtTmp.getDate());
if (mStr.panjang==1){
mStr="0"+mStr;
}
jika (dStr.panjang==1){
dStr="0"+dStr;
}
kembalikan dtTmp.getFullYear()+"-"+mStr+"-"+dStr;
}
</skrip>
<script bahasa = "JavaScript">
fungsi menghitung (ketik)
{
entri var = document.getElementById(type).value;//自己判断是否合法
var uValue=dokumen.form.u.value;
uValue=uValue.replace("-","/").replace("-","/");
//peringatan(nilaiu);
document.form.twice.value = DateAdd(type,entry,uValue);
}
</skrip>