版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、基于Firefox / IE 瀏覽器的日歷控件程序是以 腳本之家 流行的 基于IE瀏覽器的Calendar.js程序?yàn)槟0?,?jīng)多人修改完善,現(xiàn) 支持多版本瀏覽器,需要兩個(gè)文件WebCalendar.js與WebCalendar.html具體代碼如下WebCalendar.js/*-基于IE / Firefox瀏覽器-*/var cal;var isFocus=false; /是否為焦點(diǎn)var pickMode ="second":1,"minute":2,"hour":3,"day":4,"month&q
2、uot;:5,"year":6 ;var topY=0,leftX=0; /自定義定位偏移量/選擇日期 通過 ID 來選日期function SelectDateById(id,strFormat,x,y) var obj = document.getElementById(id); if(obj = null)return false; obj.focus(); if(obj.onclick != null)obj.onclick(); else if(obj.click != null)obj.click(); elseSelectDate(obj,strFormat,
3、x,y)/選擇日期 function SelectDate(obj,strFormat,x,y) leftX =(x = null) ? leftX : x; topY =(y = null) ? topY : y;/自定義定位偏移量 if(document.getElementById("ContainerPanel")=null)InitContainerPanel();var date = new Date();var by = date.getFullYear()-50; /最小值 50 年前var ey = date.getFullYear()+50; /最大值
4、50 年后/cal = new Calendar(by, ey,1,strFormat); /初始化英文版,0 為中文版cal = (cal=null) ? new Calendar(by, ey, 0) : cal; /不用每次都初始化cal.DateMode =pickMode"second" /復(fù)位if(strFormat.indexOf('s')< 0) cal.DateMode =pickMode"minute"/精度為分if(strFormat.indexOf('m')< 0) cal.DateMo
5、de =pickMode"hour"/精度為時(shí)if(strFormat.indexOf('h')< 0) cal.DateMode =pickMode"day"/精度為日if(strFormat.indexOf('d')< 0) cal.DateMode =pickMode"month"/精度為月if(strFormat.indexOf('M')< 0) cal.DateMode =pickMode"year"/精度為年if(strFormat.in
6、dexOf('y')< 0) cal.DateMode =pickMode"second"/默認(rèn)精度為秒cal.dateFormatStyleOld = cal.dateFormatStyle;cal.dateFormatStyle = strFormat;cal.show(obj);/*/*/*/*/*/*/*/* 返回日期* param d the delimiter* param p the pattern of your date根據(jù)用戶指定的 style 來確定;*/Stotype.toDate = function(sty
7、le) var y = this.substring(style.indexOf('y'),style.lastIndexOf('y')+1);/年var M = this.substring(style.indexOf('M'),style.lastIndexOf('M')+1);/月var d = this.substring(style.indexOf('d'),style.lastIndexOf('d')+1);/日var h = this.substring(style.indexOf(&
8、#39;h'),style.lastIndexOf('h')+1);/時(shí)var m = this.substring(style.indexOf('m'),style.lastIndexOf('m')+1);/分var s = this.substring(style.indexOf('s'),style.lastIndexOf('s')+1);/秒if(s = null |s = "" | isNaN(s) s = new Date().getSeconds();if(m = null
9、 |m = "" | isNaN(m) m = new Date().getMinutes();if(h = null |h = "" | isNaN(h) h = new Date().getHours();if(d = null |d = "" | isNaN(d) d = new Date().getDate();if(M = null |M = "" | isNaN(M) M = new Date().getMonth()+1;if(y = null |y = "" | isNaN(y)
10、 y = new Date().getFullYear();var dt ;eval ("dt = new Date('"+ y+"', '"+(M-1)+"','"+ d+"','"+ h+"','"+ m+"','"+ s +"')");return dt;/*/*/*/*/*/*/*/* 格式化日期* param d the delimiter* para
11、m p the pattern of your date* author meizz*/Dtotype.format = function(style) var o = "M+" : this.getMonth() + 1, /month"d+" : this.getDate(), /day"h+" : this.getHours(), /hour"m+" : this.getMinutes(), /minute"s+" : this.getSeconds(), /second&q
12、uot;w+" : "天一二三四五六".charAt(this.getDay(), /week"q+" : Math.floor(this.getMonth() + 3) / 3), /quarter"S" : this.getMilliseconds() /millisecondif(/(y+)/.test(style) style = style.replace(RegExp.$1,(this.getFullYear() + "").substr(4 - RegExp.$1.length);for(v
13、ar k in o)if(new RegExp("("+ k +")").test(style)style = style.replace(RegExp.$1,RegExp.$1.length = 1 ? ok :("00" + ok).substr("" + ok).length);return style;Ctotype.ReturnDate = function(dt) if (this.dateControl != null)this.dateControl.value = dt;ca
14、lendar.hide(); if(this.dateControl.onchange = null)return; /將 onchange 轉(zhuǎn)成其它函數(shù),以免觸發(fā)驗(yàn)證事件var ev = this.dateControl.onchange.toString(); /找出函數(shù)的字串ev = ev.substring( (ev.indexOf("ValidatorOnChange();")> 0) ? ev.indexOf("ValidatorOnChange();") + 20 : ev.indexOf("") + 1) , e
15、v.lastIndexOf("");/去除驗(yàn)證函數(shù) ValidatorOnChange(); var fun = new Function(ev); /重新定義函數(shù) this.dateControl.changeEvent = fun; this.dateControl.changeEvent();/觸發(fā)自定義 changeEvent 函數(shù)/*/*/*/*/*/*/*/* 日歷類* param beginYear 1990* param endYear 2010* param lang 0(中文)|1(英語) 可自由擴(kuò)充* param dateFormatStyle &qu
16、ot;yyyy-MM-dd"* version 2006-04-01* author KimSoft (jinqinghua at )* update*/function Calendar(beginYear, endYear, lang, dateFormatStyle) this.beginYear = 1950;this.endYear = 2050;this.lang = 0; /0(中文) | 1(英文)this.dateFormatStyle = "yyyy-MM-dd hh:mm:ss"if (beginYear != null &&
17、 endYear != null)this.beginYear = beginYear;this.endYear = endYear;if (lang != null)this.lang = langif (dateFormatStyle != null)this.dateFormatStyle = dateFormatStylethis.dateControl = null;this.panel = this.getElementById("calendarPanel");this.container = this.getElementById("Contain
18、erPanel");this.form = null;this.date = new Date();this.year = this.date.getFullYear();this.month = this.date.getMonth();this.day = this.date.getDate();this.hour = this.date.getHours();this.minute = this.date.getMinutes();this.second = this.date.getSeconds();this.colors = "cur_word" :
19、"#FFFFFF", /當(dāng)日日期文字顏色"cur_bg" : "#00FF00", /當(dāng)日日期單元格背影色"sel_bg" : "#FFCCCC", /已被選擇的日期單元格背影色"sun_word" : "#FF0000", /星期天文字顏色"sat_word" : "#0000FF", /星期六文字顏色"td_word_light" : "#333333", /單元格文字顏色
20、"td_word_dark" : "#CCCCCC", /單元格文字暗色"td_bg_out" : "#EFEFEF", /單元格背影色"td_bg_over" : "#FFCC00", /單元格背影色"tr_word" : "#FFFFFF", /日歷頭文字顏色"tr_bg" : "#666666", /日歷頭背影色"input_border" : "#CCCCCC
21、", /input控件的邊框顏色"input_bg" : "#EFEFEF" /input控件的背影色/* /放到了 show ,因?yàn)橐?pickMode 判斷this.draw();this.bindYear();this.bindMonth();*/this.changeSelect();/this.bindData();/*/*/*/*/*/*/*/* 日歷類屬性(語言包,可自由擴(kuò)展)*/Calendar.language = "year" : "", "","mon
22、ths" : "一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月","JAN","FEB","MAR","APR","MAY","JUN","JUL&
23、quot;,"AUG","SEP","OCT","NOV","DEC","weeks" : "日","一","二","三","四","五","六","SUN","MON","TUR","WED","THU","FRI",
24、"SAT","hour" : "時(shí)", "H","minute" : "分", "M","second" : "秒", "S","clear" : "清空", "CLS","today" : "今天", "TODAY","pickTxt" : "確定
25、", "OK",/pickMode 精確到年、月時(shí)把今天變成“確定”"close" : "關(guān)閉", "CLOSE"Ctotype.draw = function() calendar = this;var mvAry = ;/mvArymvAry.length = ' <form name="calendarForm" style="margin: 0px;">' /因 <form> 不能嵌套改用 Div
26、mvArymvAry.length = ' <div name="calendarForm" style="margin: 0px;">'mvArymvAry.length = ' <table width="100%" border="0" cellpadding="0" cellspacing="1" style="font-size:12px;">'mvArymvAry.length =
27、9; <tr>'mvArymvAry.length = ' <th align="left" width="1%"><input style="border: 1px solid ' + calendar.colors"input_border" + 'background-color:' + calendar.colors"input_bg" + 'width:16px;height:20px;'if(calendar
28、.DateMode > pickMode"month")mvArymvAry.length = 'display:none;'/pickMode 精確到年時(shí)隱藏“月”mvArymvAry.length ='" name="prevMonth" type="button" id="prevMonth" value="<" /></th>'mvArymvAry.length = ' <th align=&q
29、uot;center" width="98%" nowrap="nowrap"><select name="calendarYear" id="calendarYear" style="font-size:12px;"></select><select name="calendarMonth" id="calendarMonth" style="font-size:12px;'if(calen
30、dar.DateMode > pickMode"month")mvArymvAry.length = 'display:none;'/pickMode 精確到年時(shí)隱藏“月”mvArymvAry.length = '"></select></th>'mvArymvAry.length = ' <th align="right" width="1%"><input style="border: 1px solid '
31、+ calendar.colors"input_border" + 'background-color:' + calendar.colors"input_bg" + 'width:16px;height:20px;'if(calendar.DateMode > pickMode"month")mvArymvAry.length = 'display:none;'/pickMode 精確到年時(shí)隱藏“月”mvArymvAry.length ='" name=&quo
32、t;nextMonth" type="button" id="nextMonth" value=">" /></th>'mvArymvAry.length = ' </tr>'mvArymvAry.length = ' </table>'mvArymvAry.length = ' <table id="calendarTable" width="100%" style=&quo
33、t;border:0px solid #CCCCCC;background-color:#FFFFFF;font-size:12px;'if(calendar.DateMode >= pickMode"month")mvArymvAry.length = 'display:none;'/pickMode 精確到年、月時(shí)隱藏“天”mvArymvAry.length = '" border="0" cellpadding="3" cellspacing="1">
34、39;mvArymvAry.length = ' <tr>'for(var i = 0; i < 7; i+) mvArymvAry.length = ' <th style="font-weight:normal;background-color:' + calendar.colors"tr_bg" + 'color:' + calendar.colors"tr_word" + '">' + Calendar.language"w
35、eeks"this.langi + '</th>'mvArymvAry.length = ' </tr>'for(var i = 0; i < 6;i+)mvArymvAry.length = ' <tr align="center">'for(var j = 0; j < 7; j+) if (j = 0)mvArymvAry.length = ' <td style="cursor:default;color:' + calendar
36、.colors"sun_word" + '"></td>' else if(j = 6) mvArymvAry.length = ' <td style="cursor:default;color:' + calendar.colors"sat_word" + '"></td>' else mvArymvAry.length = ' <td style="cursor:default;"><
37、/td>'mvArymvAry.length = ' </tr>'/2009-03-03 添加的代碼,放置時(shí)間的行mvArymvAry.length = ' <tr style="'if(calendar.DateMode >= pickMode"day")mvArymvAry.length = 'display:none;'/pickMode 精確到時(shí)日隱藏“時(shí)間”mvArymvAry.length = '"><td align="cen
38、ter" colspan="7">'mvArymvAry.length = ' <select name="calendarHour" id="calendarHour" style="font-size:12px;"></select>' + Calendar.language"hour"this.lang;mvArymvAry.length = '<span style="'if(calendar
39、.DateMode >= pickMode"hour")mvArymvAry.length = 'display:none;'/pickMode 精確到小時(shí)時(shí)隱藏“分”mvArymvAry.length = '"><select name="calendarMinute" id="calendarMinute" style="font-size:12px;"></select>' + Calendar.language"minu
40、te"this.lang+'</span>'mvArymvAry.length = '<span style="'if(calendar.DateMode >= pickMode"minute")mvArymvAry.length = 'display:none;'/pickMode 精確到小時(shí)、分時(shí)隱藏“秒”mvArymvAry.length = '"><select name="calendarSecond" id="c
41、alendarSecond" style="font-size:12px;"></select>'+ Calendar.language"second"this.lang+'</span>'mvArymvAry.length = ' </td></tr>'mvArymvAry.length = ' </table>'/mvArymvAry.length = ' </from>'mvArymvAry
42、.length = ' <div align="center" style="padding:4px 4px 4px 4px;background-color:' + calendar.colors"input_bg" + '">'mvArymvAry.length = ' <input name="calendarClear" type="button" id="calendarClear" value="
43、' + Calendar.language"clear"this.lang + '" style="border: 1px solid ' + calendar.colors"input_border" + 'background-color:' + calendar.colors"input_bg" + 'width:40px;height:20px;font-size:12px;cursor:pointer;"/>'mvArymvAry.l
44、ength = ' <input name="calendarToday" type="button" id="calendarToday" value="'mvArymvAry.length = (calendar.DateMode = pickMode"day") ? Calendar.language"today"this.lang : Calendar.language"pickTxt"this.lang;mvArymvAry.leng
45、th = '" style="border: 1px solid ' + calendar.colors"input_border" + 'background-color:' + calendar.colors"input_bg" + 'width:60px;height:20px;font-size:12px;cursor:pointer"/>'mvArymvAry.length = ' <input name="calendarClose&q
46、uot; type="button" id="calendarClose" value="' + Calendar.language"close"this.lang + '" style="border: 1px solid ' + calendar.colors"input_border" + 'background-color:' + calendar.colors"input_bg" + 'width:40px;
47、height:20px;font-size:12px;cursor:pointer"/>'mvArymvAry.length = ' </div>'mvArymvAry.length = ' </div>'this.panel.innerHTML = mvAry.join("");var obj = this.getElementById("prevMonth");obj.onclick = function () calendar.goPrevMonth(calendar)
48、;obj.onblur = function () calendar.onblur();this.prevMonth= obj;obj = this.getElementById("nextMonth");obj.onclick = function () calendar.goNextMonth(calendar);obj.onblur = function () calendar.onblur();this.nextMonth= obj;obj = this.getElementById("calendarClear");obj.onclick =
49、function () calendar.ReturnDate(""); /*calendar.dateControl.value = ""calendar.hide();*/this.calendarClear = obj;obj = this.getElementById("calendarClose");obj.onclick = function () calendar.hide();this.calendarClose = obj;obj = this.getElementById("calendarYear&qu
50、ot;);obj.onchange = function () calendar.update(calendar);obj.onblur = function () calendar.onblur();this.calendarYear = obj;obj = this.getElementById("calendarMonth");with(obj)onchange = function () calendar.update(calendar);onblur = function () calendar.onblur();this.calendarMonth = obj;
51、obj = this.getElementById("calendarHour");obj.onchange = function () calendar.hour = this.optionsthis.selectedIndex.value;obj.onblur = function () calendar.onblur();this.calendarHour = obj;obj = this.getElementById("calendarMinute");obj.onchange = function () calendar.minute = th
52、is.optionsthis.selectedIndex.value;obj.onblur = function () calendar.onblur();this.calendarMinute = obj;obj = this.getElementById("calendarSecond");obj.onchange = function () calendar.second = this.optionsthis.selectedIndex.value;obj.onblur = function () calendar.onblur();this.calendarSeco
53、nd = obj;obj = this.getElementById("calendarToday");obj.onclick = function () var today = (calendar.DateMode != pickMode"day") ?new Date(calendar.year,calendar.month,calendar.day,calendar.hour,calendar.minute,calendar.second): new Date();calendar.ReturnDate(today.format(calendar.
54、dateFormatStyle);this.calendarToday = obj;/年份下拉框綁定數(shù)據(jù)Ctotype.bindYear = function() var cy = this.calendarYear;cy.length = 0;for (var i = this.beginYear; i <= this.endYear; i+)cy.optionscy.length = new Option(i + Calendar.language"year"this.lang, i);/月份下拉框綁定數(shù)據(jù)Ctotype
55、.bindMonth = function() var cm = this.calendarMonth;cm.length = 0;for (var i = 0; i < 12; i+)cm.optionscm.length = new Option(Calendar.language"months"this.langi, i);/小時(shí)下拉框綁定數(shù)據(jù)Ctotype.bindHour = function() var ch = this.calendarHour;if(ch.length > 0)return;/不需要重新綁定,提高性能/ch
56、.length = 0;var h;for (var i = 0; i < 24; i+)h = ("00" + i +"").substr("" + i).length);ch.optionsch.length = new Option(h, h);/分鐘下拉框綁定數(shù)據(jù)Ctotype.bindMinute = function() var cM = this.calendarMinute;if(cM.length > 0)return;/不需要重新綁定,提高性能/cM.length = 0;var
57、M;for (var i = 0; i < 60; i+)M = ("00" + i +"").substr("" + i).length);cM.optionscM.length = new Option(M, M);/秒鐘下拉框綁定數(shù)據(jù)Ctotype.bindSecond = function() var cs = this.calendarSecond;if(cs.length > 0)return;/不需要重新綁定,提高性能/cs.length = 0;var s;for (var i = 0
58、; i < 60; i+)s = ("00" + i +"").substr("" + i).length);cs.optionscs.length = new Option(s, s);/向前一月Ctotype.goPrevMonth = function(e)if (this.year = this.beginYear && this.month = 0)return;this.month-;if (this.month = -1) this.year-;this.month = 11;
59、this.date = new Date(this.year, this.month, 1);this.changeSelect();this.bindData();/向后一月Ctotype.goNextMonth = function(e)if (this.year = this.endYear && this.month = 11)return;this.month+;if (this.month = 12) this.year+;this.month = 0;this.date = new Date(this.year, this.month, 1)
60、;this.changeSelect();this.bindData();/改變SELECT選中狀態(tài)Ctotype.changeSelect = function() var cy = this.calendarYear;var cm = this.calendarMonth;var ch = this.calendarHour;var cM = this.calendarMinute;var cs = this.calendarSecond;/減少運(yùn)算次數(shù)cythis.date.getFullYear()-this.beginYear.selected = true;c
61、mthis.date.getMonth().selected =true;/初始化時(shí)間的值chthis.hour.selected =true;cMthis.minute.selected =true;csthis.second.selected =true;/更新年、月Ctotype.update = function (e)this.year = e.calendarYear.optionse.calendarYear.selectedIndex.value;this.month = e.calendarMonth.optionse.calendarMonth.sel
62、ectedIndex.value;this.date = new Date(this.year, this.month, 1);/this.changeSelect();this.bindData();/綁定數(shù)據(jù)到月視圖Ctotype.bindData = function () var calendar = this; if(calendar.DateMode >= pickMode"month")return;/2008-01-29/ var dateArray = this.getMonthViewArray(this.date.getYe
63、ar(), this.date.getMonth();/在Firefox 下年份錯(cuò)誤var dateArray = this.getMonthViewArray(this.date.getFullYear(), this.date.getMonth();var tds = this.getElementById("calendarTable").getElementsByTagName("td");for(var i = 0; i < tds.length; i+) tdsi.style.backgroundColor = calendar.col
64、ors"td_bg_out"tdsi.onclick = function () return;tdsi.onmouseover = function () return;tdsi.onmouseout = function () return;if (i > dateArray.length - 1) break;tdsi.innerHTML = dateArrayi;if (dateArrayi != " ")tdsi.bgColorTxt = "td_bg_out" /保存背景色的classvar cur
65、 = new Date();tdsi.isToday = false;if (cur.getFullYear() = calendar.date.getFullYear() && cur.getMonth() = calendar.date.getMonth() && cur.getDate() = dateArrayi) /是今天的單元格tdsi.style.backgroundColor = calendar.colors"cur_bg"tdsi.bgColorTxt = "cur_bg"tdsi.isToday = true;if(calendar.dateControl != null )cur = calendar.dateControl.value.toDate(calendar.dateFormatStyle);if (cur.getFullYear() = calendar.date.getFullYear() && cur.getMonth() = calendar.date.getMonth()&& cur
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度豬肉品牌線上線下聯(lián)動(dòng)推廣合同3篇
- 二零二五年度關(guān)于鄰居拆墻的社區(qū)設(shè)施共建合同3篇
- 二零二五年度幼兒園幼兒早教課程開發(fā)與推廣承包合同3篇
- 二零二五年度勞動(dòng)電子合同電子檔案?jìng)浞菖c恢復(fù)服務(wù)協(xié)議3篇
- 2025年度公廁安全監(jiān)控系統(tǒng)安裝與維護(hù)承包施工合同書3篇
- 2025年度數(shù)據(jù)中心機(jī)房建設(shè)分包施工合同
- 二零二五年度公司代付員工社保及補(bǔ)充醫(yī)療保險(xiǎn)合同3篇
- 二零二五年度農(nóng)產(chǎn)品自產(chǎn)自銷農(nóng)產(chǎn)品電商平臺(tái)入駐合同3篇
- 《家裝知識(shí)講座》課件
- 《癲癇本科》課件
- 培訓(xùn)機(jī)構(gòu)五年發(fā)展規(guī)劃方案
- 《銷售主管競(jìng)聘》課件
- 青少年型青光眼個(gè)案護(hù)理
- 2024年形式與政策論文
- 機(jī)電設(shè)備故障診斷與維修(高職)全套教學(xué)課件
- 建設(shè)銀行新員工培訓(xùn)方案
- 2024年綠色生產(chǎn)培訓(xùn)資料
- 醫(yī)院藥房年終工作總結(jié)
- 整體爬升鋼平臺(tái)模板工程技術(shù)規(guī)程
- 2024年醫(yī)療管理趨勢(shì)展望挑戰(zhàn)與機(jī)遇培訓(xùn)課件
- 發(fā)動(dòng)機(jī)無法啟動(dòng)的故障診斷
評(píng)論
0/150
提交評(píng)論