javascript實現(xiàn)考勤日歷功能
簡介
用過一些開源的日歷,但對于自定義去綁定數(shù)據(jù)在日歷元素中卻不是很方便,由于工作需要用到考勤日歷,考慮到日歷的實現(xiàn)也不是特別麻煩,于是自己弄了一個,樣式比較簡單,需要的可以自己去擴(kuò)展。使用的時候綁定獲取數(shù)據(jù)的方法即可,在這個日歷中我沒有直接添加選擇月份。各位有興趣可以自己擴(kuò)展,已預(yù)留設(shè)置日期的方法。自定義去擴(kuò)展的時候注意保證原有的代碼結(jié)構(gòu)不變,增加一些方法即可,下面直接上源碼了,就三個文件。
attendanceCalendar.js
代碼已更新多次,請直接上github下載,鏈接
修復(fù) 第一行日期數(shù)量計算 bug,修改了以下的方法
function initCalendarBody() {
$content = document.createElement("div");
addClass($content, "div_calendar_body");
$elem.appendChild($content);
addCalendarHead();
//日期計算bug,例:2017-01
var num = 0;
do {
var length = 0;
if (num == 0) {
//出星期天外,星期數(shù)(1~6)和第一行顯示的日期數(shù)(7~2),相加的結(jié)果都為8
length = firstWeekDay == 0 ? 1 : 8 - firstWeekDay;
num = length;
createLine(length - 1, 1);
}
else {
var length = mds - num > 6 ? 7 : mds - num;
num = num + length;
createLine(length - 1);
}
}
while (num < mds)
showCurrentDate();
}
function createLine(num, type) {
var newDiv = document.createElement("div");
for (var i = 0; i <= num; i++, index++) {
var span = document.createElement("span");
var span_text = document.createTextNode(index + 1);
//單個日期元素的操作
if (attendances && attendances.length > 0) {
bindAttendance(span, attendances[index]);
}
span.appendChild(span_text);
newDiv.appendChild(span);
}
if (type == 1) {
addClass(newDiv, "first_div")
}
else {
addClass(newDiv, "last_div")
}
$content.appendChild(newDiv);
}
css部分,日期元素主要用了三種顏色表示
.div_calendar {
width: 450px;
margin: 0 auto;
text-align: center;
display: -webkit-box;
}
/** 日歷標(biāo)題 */
.div_calendar_title {
width: 450px;
margin: 0 auto;
text-align: center;
}
/** 日歷主體 */
.div_calendar_body {
width: 350px;
text-align: center;
}
/** 日元素 */
.div_calendar span {
width: 50px;
display: inline-block;
text-align: center;
line-height: 50px;
}
/** 正常 */
.div_calendar span.normal {
color: blue;
}
/** 遲到 */
.div_calendar span.late {
color: red;
}
/** 缺勤 */
.div_calendar span.absense {
color: #666;
}
/** 缺勤 */
.div_calendar span.today {
border-radius: 50%;
background: cornflowerblue;
}
/** 日歷第一行日期 */
.div_calendar .first_div {
text-align: right;
}
/** 日歷末行日期 */
.div_calendar .last_div {
text-align: left;
}
/** 日期顯示div */
.div_calendar .div_currentDate {
text-align: right;
}
.div_calendar .changeDate {
cursor: pointer;
}
.div_calendar .div_currentDate span {
width: inherit;
}
.div_calendar .div_currentDate span em {
margin: 5px;
}
calendar.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="div_calendar_title"><h1>自定義日歷</h1></div> <div id="calendar_div" class="div_calendar"> </div> <script src="script/attendanceCalendar.js"></script> </body> </html>
示例演示:

代碼已更新多次,請直接上github下載,鏈接
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js實現(xiàn)點(diǎn)擊向下展開的下拉菜單效果代碼
這篇文章主要介紹了js實現(xiàn)點(diǎn)擊向下展開的下拉菜單效果代碼,涉及javascript鼠標(biāo)事件控制頁面元素樣式變換的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-09-09
微信小程序scroll-view實現(xiàn)滾動到錨點(diǎn)左側(cè)導(dǎo)航欄點(diǎn)餐功能(點(diǎn)擊種類,滾動到錨點(diǎn))
這篇文章主要介紹了微信小程序scroll-view左側(cè)導(dǎo)航欄點(diǎn)餐功能實現(xiàn),點(diǎn)擊種類,滾動到錨點(diǎn);滾動到錨點(diǎn),種類選中,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06
openLayer4實現(xiàn)動態(tài)改變標(biāo)注圖標(biāo)
這篇文章主要為大家詳細(xì)介紹了openLayer4實現(xiàn)動態(tài)改變標(biāo)注圖標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-08-08
Javascript實現(xiàn)仿QQ隨機(jī)數(shù)驗證
這篇文章主要為大家詳細(xì)介紹了Javascript實現(xiàn)仿QQ隨機(jī)數(shù)驗證,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05
一文快速學(xué)會創(chuàng)建uni-app項目并了解pages.json文件
這篇文章主要給大家介紹了如何創(chuàng)建uni-app項目并了解pages.json文件的相關(guān)資料,pages.json文件用來對uni-app進(jìn)行全局配置,決定頁面文件的路徑、窗口樣式、原生的導(dǎo)航欄、底部的原生tabbar等,需要的朋友可以參考下2023-10-10
ASP中進(jìn)行HTML數(shù)據(jù)及JS數(shù)據(jù)編碼函數(shù)
在有些時候我們無法控制亂碼的出現(xiàn), 比如發(fā)送郵件的時候有些郵件顯示亂碼, 比如Ajax返回數(shù)據(jù)總是亂碼. 怎么辦?2009-11-11

