復制代碼 代碼如下:
<html>
<head>
<script language="javascript" type="text/javascript">
/** 日期比較 **/
function compareDate(strDate1,strDate2)
{
var date1 = new Date(strDate1.replace(//-/g, "http://"));
var date2 = new Date(strDate2.replace(//-/g, "http://"));
return date1-date2;
}
/** 比較 **/
function doCompare(){
var strDate1 = document.getElementById("strDate1").value;
var strDate2 = document.getElementById("strDate2").value;
var result = compareDate(strDate1,strDate2);
if ( result>0 ) {
alert("strDate1晚于strDate2");
}else if( result<0 ){
alert("strDate1早于strDate2");
}else if ( result==0 ){
alert("strDate1等于strDate2");
}
}
</script>
</head>
<body>
<input type="text" value="2012-07-01"/>
<input type="text" value="2012-08-01"/>
<input type="button" value="比較"/>
</body>
</html>
新聞熱點
疑難解答
圖片精選