這篇文章主要講解了javascript實現(xiàn)日歷功能的方法,內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。
創(chuàng)新互聯(lián)作為成都網(wǎng)站建設(shè)公司,專注重慶網(wǎng)站建設(shè)公司、網(wǎng)站設(shè)計,有關(guān)企業(yè)網(wǎng)站建設(shè)方案、改版、費用等問題,行業(yè)涉及濕噴機等多個領(lǐng)域,已為上千家企業(yè)服務(wù),得到了客戶的尊重與認(rèn)可。
日歷
在學(xué)習(xí)javascript過程中,菜鳥教程有一個javascript實例---css日歷,感覺挺有趣的,在它的基礎(chǔ)上增加了一些簡單的功能(差點哭遼)。
功能
實現(xiàn)
代碼
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
看完上述內(nèi)容,是不是對javascript實現(xiàn)日歷功能的方法有進一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。