4.9w+
社区成员
<!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>无标题文档 </title>
</head>
<script>
function getTime(obj){
var stime=document.getElementById('ksrq').value;
var etime=document.getElementById('zzrq').value;
var stime1=stime.split("-");
var etime1=etime.split("-");
stime=stime1[1]+"/"+stime1[2]+"/"+stime1[0];
etime=etime1[1]+"/"+etime1[2]+"/"+etime1[0];
var days=Math.ceil((Date.parse(etime)-Date.parse(stime))/1000/60/60/24);//时间差:天
var monthE = Math.round(days/30); //时间差:按30天一个月算,4舍5入。
obj.value=monthE;
}
</script>
<body>
<input name="ksrq" id="ksrq" type=text value=2009-01-01>
<input name="zzrq" id="zzrq" type=text value=2009-11-01>
<input type=text name=myno size=20 onfocus="getTime(this)"/>
</body>
</html>