符合中小企业对网站设计、功能常规化式的企业展示型网站建设
本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...
商城网站建设因基本功能的需求不同费用上面也有很大的差别...
手机微信网站开发、微信官网、微信商城网站...
这篇文章主要讲解了javascript实现日历功能的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。
创新互联作为成都网站建设公司,专注重庆网站建设公司、网站设计,有关企业网站建设方案、改版、费用等问题,行业涉及湿喷机等多个领域,已为上千家企业服务,得到了客户的尊重与认可。
日历
在学习javascript过程中,菜鸟教程有一个javascript实例---css日历,感觉挺有趣的,在它的基础上增加了一些简单的功能(差点哭辽)。
功能
实现
代码
html代码
CSS日历 CSS日历
- ❮
- ❯
- August
2016
CSS代码
@charset "UTF-8"; * {box-sizing:border-box;} ul {list-style-type: none;} body {font-family: Verdana,sans-serif;} .center { text-align: center; border: 3px solid green; } .month { padding: 70px 25px; width: 100%; background: #1abc9c; } .month ul { margin: 0; padding: 0; } .month ul li { color: white; font-size: 20px; text-transform: uppercase; letter-spacing: 3px; } .month .prev { float: left; padding-top: 10px; } .month .next { float: right; padding-top: 10px; } .weekdays { margin: 0; padding: 10px 0; background-color: #ddd; } .weekdays li { display: inline-block; width: 13.6%; color: #666; text-align: center; } .days { padding: 10px 0; background: #eee; margin: 0; } .days li { list-style-type: none; display: inline-block; width: 13.6%; text-align: center; margin-bottom: 5px; font-size:12px; color: #777; } .days li active { padding: 5px; background: #1abc9c; color: white !important; } /* Add media queries for smaller screens */ @media screen and (max-width:720px) { .weekdays li, .days li {width: 13.1%;} } @media screen and (max-width: 420px) { .weekdays li, .days li {width: 12.5%;} .days li .active {padding: 2px;} } @media screen and (max-width: 290px) { .weekdays li, .days li {width: 12.2%;} }
javascript代码
var date = new Date(); var year = date.getFullYear(); var month=date.getMonth(); var day = date.getDate(); var week=date.getDay(); var p=(week-day+1+35)%7+day-1; var monthName=[ "January","February","March","April","May","June","July","August","September","October","November","December" ]; var monthNum=[ 31,28,31,30,31,30,31,31,30,31,30,31 ]; var weekName=[ "Su","Mo","Tu","We","Th","Fr","Sa" ]; var aimmonth=month,aimyear=year; function init(){ createTitle(year,month); var weekdays=document.getElementById("weekdays"); for(var i=0;i<7;i++){ var x = document.createElement("LI"); var t = document.createTextNode(weekName[i]); x.appendChild(t); weekdays.appendChild(x); } delDay(); createDay(); isnow(); } function change(x){ aimmonth+=x; if(aimmonth==-1){ aimyear-=1; aimmonth=11; }else if(aimmonth==12){ aimyear+=1; aimmonth=0; } createTitle(aimyear,aimmonth); delDay(); createDay(); isnow(); } function createTitle(y,m){ document.getElementById("year").innerHTML=y; document.getElementById("month").innerHTML=monthName[m]; } function createDay(){ var datetmp=new Date(); datetmp.setFullYear(aimyear,aimmonth,1); var firstday=datetmp.getDay(); var days=document.getElementById("days"); for(var i=0;i
看完上述内容,是不是对javascript实现日历功能的方法有进一步的了解,如果还想学习更多内容,欢迎关注创新互联行业资讯频道。