發表于:2011-07-05 00:00:00來源:SOUAB.COM人氣:3685
<script language="javascript">
function CheckForm()
{
var jsrq=document.getElementById("sLtime").value; //結束
var ksrq=document.getElementById("sRtime").value; //開(kāi)始
var now=""+new Date().getYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate()+"";
var aDate = jsrq.split("-");
var oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //結束日期
aDate = ksrq.split("-");
var oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //開(kāi)始日期
if(oDate1<=oDate2) {
alert("結束日期必須大(dà)于開(kāi)始日期!");
return false;
}
else {
var ts = dateDiff('D', ksrq, jsrq) ;
//document.getElementById("iDays").value=ts
if(ts>=30)
{
alert('時間段不能超過30天');
return false;
}
}
}
function dateDiff(interval, date1, date2)
{
var objInterval = {'D' : 1000 * 60 * 60 * 24, 'H' : 1000 * 60 * 60,
'M' : 1000 * 60, 'S' : 1000, 'T' : 1};
interval = interval.toUpperCase();
var dt1 = Date.parse(date1.replace(/-/g, '/'));
var dt2 = Date.parse(date2.replace(/-/g, '/'));
try
{
return Math.round((dt2 - dt1) / eval('(objInterval.' + interval + ')'));
}
catch (e)
{
return e.message;
}
}
</script>