发表于:2011-07-05 00:00:00来源:SOUAB.COM人气:3848
<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]); //结束日期
aDate = ksrq.split("-");
var oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //开始日期
if(oDate1<=oDate2) {
alert("结束日期必须大于开始日期!");
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>