javascript - jquery怎么写显示今天后2周的日历
本文介绍了javascript - jquery怎么写显示今天后2周的日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
只显示今天后2周内的日历,移动端微信页面用的,有插件吗,没插件如何写呢?js手写也行,谢谢
解决方案
写了一个试试看。
<!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 src='jquery.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;
for (i = 1; i < thisWeeKDay; i++) {
dateArr.push('whiteSpace');
}
for (i = 0; i <= distance; i++) {
dateArr.push({
Day: year + '-' + (+month + 1) + '-' + TodayDay++
})
}
if (month == 11) {
month =-1;
year++;
};
for (i = 1; i < left; i++) {
dateArr.push({
Day: year + '-' + (+month + 2) + '-' + i
})
};
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>
这篇关于javascript - jquery怎么写显示今天后2周的日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文