打印2018年的日历
Posted liuhao-web
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打印2018年的日历相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{box-sizing: border-box;}
.calendar{
float:left;
width:25%;
border: 1px solid #eee
}
.calendar .calendar_title{
padding:.5em 0 .5em 0;
text-align: center;
border-bottom: 1px solid #eee
}
.calendar .calendar_week{
padding:.5em 0 .5em 0;
}
.calendar .calendar_week span{
width:14.2857%;
text-align: center;
display: inline-block;
}
.calendar .calendar_dateCon span{
padding:.5em 0 .5em 0;
width:14.2857%;
text-align: center;
display: inline-block;
}
</style>
</head>
<body>
<div id="rili"></div>
<script type="text/javascript">
var year="2018";
var month="05";
var strr=""
for(var c=1;c<=12;c++){
strr+=createRi(year,c);
}
document.getElementById("rili").innerHTML=strr
function createRi(year,month){
var str=‘<div class="calendar">
<div class="calendar_title">{{month}}月</div>
<div class="calendar_week">
<span>周日</span><span>周一</span><span>周二</span><span>周三</span><span>周四</span><span>周五</span><span>周六</span>
</div>
<div class="calendar_dateCon">{{days}}</div>
</div>‘
var str=str.replace("{{month}}",month);
var emptySpan=getMonthFirstDayWeek(year,month);
var days=getDay(year,month);
var spanStr=""
for(var k=0;k<emptySpan;k++){
spanStr+="<span></span>"
}
for(var n=0;n<days.length;n++){
spanStr+="<span>"+days[n]+"</span>";
}
var str=str.replace("{{days}}",spanStr);
return str;
}
function isLeapYear(year) { return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0); }
function getMonthFirstDayWeek(year,month){
var month=+month-1;
var date=new Date();
date.setFullYear(year);
date.setMonth(month);
date.setDate(1);
return date.getDay();
}
function getDay(year,month){
var month=+month;
var day31=[];
var day30=[];
var day29=[];
for(var i=1;i<=31;i++){
day31.push(i);
if(i<=30){
day30.push(i);
}
if(i<=29){
day29.push(i);
}
}
if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12){
return day31
}
if(month==4 || month==6 || month==9 || month==11){
return day30
}
if(month==2){
if(isLeapYear(year)){
return day29
}else{
return day30
}
}
}
</script></body></html>
以上是关于打印2018年的日历的主要内容,如果未能解决你的问题,请参考以下文章