判断截止日期不能小于当前日期
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>http://www.cnblogs.com/zhengxiqiang</title>
</head>
<body>
<script language="javascript" type="text/javascript">
function diftime()
{
var date=new Date();
var day=date.getDate();
var month=date.getMonth()+1
var year=date.getFullYear()
s1=year+ "-"+month+ "-"+day;
s2=document.getElementById("sdv").value;
if(DateDiff(s1,s2) < 0)
{
alert("过期日期不能小于当前日期");
return false;
}
}
function DateDiff(sDate1,sDate2)
{
var aDate,oDate1,oDate2,iDays
aDate=sDate1.split("-")
oDate1=new Date(aDate[1]+ '-'+aDate[2]+ '-'+aDate[0]) //转换为12-18-2002格式
aDate=sDate2.split("-")
oDate2=new Date(aDate[1]+ '-'+aDate[2]+ '-'+aDate[0])
iDays = parseInt(Math.abs(oDate1-oDate2)/1000/60/60/24) //把相差的毫秒数转换为天数
if(oDate1 <oDate2)
{
return iDays;
}
else
{
return -iDays ;
}
}
</script>
<form name="form1" action="" method="post" onsubmit="return diftime()">
<input type="text" name="sdv" id="sdv" />
<input name="" type="submit" value="提交" />
</form>
</body>
</html>