标签:cell var lan push div height inner head htm
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
#calender li {
list-style: none;
table-layout: fixed;
}
#calender li a {
display: table-cell;
width: 50px;
height: 50px;
}
</style>
<body>
<ul id="calender"></ul>
</body>
<script type="text/javascript" src="js/jQuery-2.1.5.min.js" ></script>
<script>
function TwoWeekCalender() {
var Today = new Date();
var TodayDay = Today.getDate();
var month = Today.getMonth();
var year = Today.getFullYear();
//获取最大天数
var mostDay = new Date(+year, +month + 1, 0).getDate();
var dateArr = [];
var distance = mostDay - TodayDay;
var thisWeeKDay = Today.getDay(); //星期
var left = 14 - distance;
var i;
console.log(mostDay,TodayDay,distance,thisWeeKDay,left)
for(i = 1; i < thisWeeKDay; i++) {
dateArr.push(‘whiteSpace‘);
}
for(i = 0; i <= distance; i++) {
dateArr.push({
Day: year + ‘-‘ + (+month + 1) + ‘-‘ + TodayDay++
})
console.log(i)
}
if(month == 11) {
month = -1;
year++;
};
for(i = 1; i < left; i++) {
dateArr.push({
Day: year + ‘-‘ + (+month + 2) + ‘-‘ + i
})
console.log(i)
};
console.log(dateArr)
var calender_html = ‘<li><a javascript:void()>星期一</a><a javascript:void()>星期二</a><a javascript:void()>星期三</a><a javascript:void()>星期四</a><a javascript:void()>星期五</a><a javascript:void()>星期六</a><a javascript:void()>星期日</a></li><li>‘;
dateArr.forEach(function(item, i) {
if(i !== 0 && i % 7 == 0) {
calender_html += ‘</li><li>‘
}
calender_html += item === ‘whiteSpace‘ ? ‘<a javascript:void()></a>‘ : ‘<a javascript:void()>‘ + item.Day + ‘</a>‘;
})
calender_html += ‘</li>‘;
document.getElementById(‘calender‘).innerHTML = calender_html;
}
TwoWeekCalender()
</script>
</html>
14:是代表从今天气到后面的14天,这个值随便(20天,这个值就写20就行)
标签:cell var lan push div height inner head htm
原文地址:https://www.cnblogs.com/yjgbk/p/9229003.html