原生js周选择器

<!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=utf-8" />
<title>无标题文档</title>
<script  type="text/javascript">
var curD = new Date();
var firstD  =  new Date();
var lastD = new Date();
var dayTime = 24*60*60*1000 ;
function initDate(){
curD.setHours(12,12,12,0);
var dateLong = curD.getTime();


if ( curD.getDay()== 0 ){
dateLong = dateLong - (6*dayTime);
}else {
dateLong = dateLong - (curD.getDay()-1)*dayTime;
}

curD.setTime(dateLong);

firstD = curD;
lastD.setTime(firstD.getTime()+6*dayTime);
var ss = firstD.getFullYear()+'-'+(firstD.getMonth()+1)+'-'+firstD.getDate()+' 至 '+lastD.getFullYear()+'-'+(lastD.getMonth()+1)+'-'+lastD.getDate();
document.getElementById('val').setAttribute('value',ss);


}

function backDate(){
var dateLong = curD.getTime();
curD.setTime(dateLong - (6*dayTime));
initDate();
}

function nextDate(){
var dateLong = curD.getTime();
curD.setTime(dateLong + (7*dayTime));
initDate();
}

</script>
</head>


<body onload="initDate();">
<a href="javascript:void(0);"  onclick="backDate();">上一周</a>
    <input  type="text"  id="val"  />
    <a href="javascript:void(0);" onclick="nextDate();" >下一周</a>
</body>
</html>

你可能感兴趣的:(html,html,html)