js生成日曆

2021-06-21 21:18:07 字數 1981 閱讀 1911

演算法:

1. 根據指定年份和月份,計算該月第一天的起始位置和最後一天的結束位置

2.第乙個單元格到起始位置,填充上個月日期或空白

3.起始位置和結束位置填充該月日期

4.結束位置之後填充下個月日期或空白

效果圖:

/**日曆初始化,預設當前月份日曆

*/function initcalendar(calendarid)

/*** calendarid: 日曆容器id

* year:4位年

* month: 0~11

*/function initcalendarnew(calendarid,year,month)

if(calendar!=null)

}}/**

* date 單元格位置與該月份第一天單元格位置的差值

* nextmonthday 單元格位置該月份最後一天單元格位置的差值

* nextflag 是否為下個月日期

*/function initcell(cell,date,days,nextmonthday,nextflag,month,week)

if(nextflag)

var showcurclass = currentdateflag?"current_date":((week==0 || week==6)?"rest_date":"normal_date");

cell.classname=currentdateflag?"selected":"";

if(previousflag)else if(nextflag)

//初始化時,如果是今天則設定為選中

selectedid = currentdateflag?days:selectedid;

cell.align="center";

var dayshtml = days>0?"第"+days+"天":"";

var html = ""+date+"

"+dayshtml+"

";    cell.innerhtml=html;

}/*初始化日曆表頭

*/function initcalendarhead(table)

}function getmonthdays(month)else if(month==2)

}return monthdays;

}function calcstart(date)

return week;

}/**

* 相容ie

*/function parsedate(val)

/*** 滑鼠滑過展示提示

*/function showdays(div,currentflag)

.hide ,.hide_pre,.hide_next

.rest_date

.rest_date_pre,.rest_date_next

.current_date

.normal_date

.normal_date_pre,.normal_date_next

.selected

div#calendar table,table.thinborder

div#calendar td

td.thinborder

.label_button

.button

.button:hover

.button:active

.white

.white:hover

.white:active

python生成日曆

按照python例項編寫python生成日曆的例項 如下 filename test.py author by www.runoob.com 引入日曆模組 from calendar import month 輸入指定年月 yy int input 輸入年份 mm int input 輸入月份 顯示...

生成日曆的SQL語句

declare year nvarchar 4 declare yearmonth nvarchar 7 月份 declare strtop nvarchar 200 declare fori int,foryear int maxday int declare rowx int 行位置 decla...

根據年月生成日曆函式

go 建立函式 第一版 dobear 0922 create function fn calendar year int month int returns nvarchar max as begin declare result nvarchar max enter nvarchar 8 sele...