码迷,mamicode.com
首页 > 其他好文 > 详细

打印2018年的日历

时间:2018-08-24 16:08:32      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:float   isp   str   create   ext   lin   javascrip   order   replace   

<!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年的日历

标签:float   isp   str   create   ext   lin   javascrip   order   replace   

原文地址:https://www.cnblogs.com/liuhao-web/p/9530045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!