首页 > jquery怎么写显示今天后2周的日历

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>
【热门文章】
【热门文章】