比较2个日期间隔的天数
<!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=gbk" />
<title>无标题文档</title>
<script type="text/javascript">
function $(id){return document.getElementById(id);}function cal(){
var d1 = $("date1").value.split("-");
var d2 = $("date2").value.split("-");
var date1 = new Date(d1[0], d1[1]-1, d1[2]);
var date2 = new Date(d2[0], d2[1]-1, d2[2]);
var day = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24);
$("result").value = day + 1;}</script></head>
<body>
<input type="text" id="date1" name="date1" value="2008-12-21" />
-<input type="text" id="date2" name="date2" value="2008-12-24" />
<input type="text" id="result" name="result" value="" />
<input type="button" id="btn" name="btn" value="计算" onclick="cal();" />
</body>
</html>