發表于:2011-07-05 00:00:00來(lái)源:SOUAB.COM人(rén)氣:3764
<script language="javascript">
function CheckForm()
{
var jsrq=document.getElementById("sLtime").value; //結束
var ksrq=document.getElementById("sRtime").value; //開始
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]); //結束日(rì)期
aDate = ksrq.split("-");
var oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //開始日(rì)期
if(oDate1<=oDate2) {
alert("結束日(rì)期必須大(dà)于開始日(rì)期!");
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>