国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

原生js實(shí)現(xiàn)日歷效果

瀏覽:122日期:2024-05-23 13:43:14

本文實(shí)例為大家分享了js實(shí)現(xiàn)日歷效果的具體代碼,供大家參考,具體內(nèi)容如下

html代碼

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <title>日歷插件</title> <link rel='stylesheet' href='http://www.cgvv.com.cn/bcjs/css/reset.css' > <link rel='stylesheet' href='http://www.cgvv.com.cn/bcjs/css/index.css' ></head><body> <div class='show'> <button id='pre'>上月</button> <span id='showtime'>2019-01</span> <button id='next'>下月</button> </div> <div id='box'> </div></body><script> // 獲取本月第一天 function getMonthDay(date){ date=new Date(date.valueOf()) date.setDate(1); return date } // 獲取本月最后一天 function getMonthLastDay(date){ date=new Date(date.valueOf()) date.setMonth(date.getMonth()+1); date.setDate(0); return date } //獲取本月的時(shí)間對(duì)象集合 function getMonth(date){ var arr=[] // 獲取本月第一天 var _date=getMonthDay(date) // // 獲取本月最后一天 var dataLast=getMonthLastDay(date).getDate() arr.push(new Date(_date.valueOf())) // 處理本月第一天 到本月最后一天 for(var i =1;i<dataLast;i++){ _date.setDate(_date.getDate()+1) arr.push(new Date(_date.valueOf())) } // 向前補(bǔ)全,重置為本月一號(hào) _date=getMonthDay(date) var forln=_date.getDay() for(var i=0;i<forln;i++){ _date.setDate(_date.getDate()-1) arr.unshift(new Date(_date.valueOf())) } // 向后補(bǔ)全,重置為本月最后一天 _date=getMonthLastDay(date) forln=_date.getDay() for(var i=forln;i<6;i++){ _date.setDate(_date.getDate()+1) arr.push(new Date(_date.valueOf())) } return arr } // 將集合渲染到頁(yè)面 function renderTable(monthDateArr,date){ document.getElementById('showtime').innerHTML=`${date.getFullYear()}-${date.getMonth()+1}` var table=document.createElement(’table’) var trTh=document.createElement(’tr’) trTh.innerHTML=` <th>周日</th> <th>周一</th> <th>周二</th> <th>周三</th> <th>周四</th> <th>周五</th> <th>周六</th> ` table.appendChild(trTh) var tr=document.createElement(’tr’) for(let i in monthDateArr){ var td=document.createElement(’td’) td.innerHTML=monthDateArr[i].getDate() tr.appendChild(td) if((i*1+1)%7===0){ table.appendChild(tr) tr=document.createElement(’tr’) }else if(i == monthDateArr.length-1){ table.appendChild(tr) } } document.getElementById('box').innerHTML=table.outerHTML } var date=new Date() document.getElementById(’pre’).onclick=function(){ date.setDate(1) date.setMonth(date.getMonth()-1) renderTable(getMonth(date),date) } document.getElementById(’next’).onclick=function(){ date.setDate(1) date.setMonth(date.getMonth()+1) rrenderTable(getMonth(date),date) } renderTable(getMonth(date),date) </script></html>

css代碼

.box{ width: 700px; margin: 0 auto; box-sizing: border-box; padding: 0 1px;}table{ width: 100%;}th,td{ width:100px; text-align: center;}th{ height: 30px; line-height: 30px; background: #e0e5e5;}td{ height: 70px; line-height: 70px; background: #f3f5f5;}.show{ display: flex; align-items: center; justify-content: center;}

更多精彩內(nèi)容請(qǐng)點(diǎn)擊專題《javascript日歷插件使用方法匯總》進(jìn)行學(xué)習(xí)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 怡红院在线视频全部观看 | 日本美女高清在线观看免费 | www.日本三级 | 成人免费a视频 | 99久久亚洲| 欧美成人久久久 | 亚洲精品国产美女在线观看 | 羞羞一区二区三区四区片 | 日韩欧美一级a毛片欧美一级 | 国产午夜不卡在线观看视频666 | 午夜香港三级a三级三点 | 正在播放国产一区 | 性视频福利在线看 | 黄色成人免费网站 | 视频一区亚洲 | 手机看福利片 | 99视频在线观看视频一区 | 欧美色网在线 | 国内精自品线一区91 | 成人男女网18免费91 | 久艹在线观看 | 免费视频一区二区 | 免费一级做a爰片久久毛片 免费一级做a爰片性色毛片 | 100000免费啪啪18免进 | a欧美| 免费精品久久久久久中文字幕 | 国产午夜亚洲精品第一区 | 久久福利青草精品资源站 | 女女互操 | 大视频在线爱爱爱爱 | 欧美激情视频一级视频一级毛片 | 亚洲爽视频 | 免费一级欧美毛片 | 一级做a爱片久久蜜桃 | 一色屋成人免费精品网 | 韩国日本一级毛片免费视频 | 怡红院美国十次成人影院 | 日本高清视频www夜色资源 | 欧美国产亚洲一区 | 一级毛片美国一级j毛片不卡 | 免费一级a毛片在线播放 |