日历控件(js)

  1 None.gif <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
  2 None.gif < html  xmlns ="http://www.w3.org/1999/xhtml" >
  3 None.gif < meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312"   />
  4 None.gif < title > 日历演示 </ title >
  5 ExpandedBlockStart.gifContractedBlock.gif < script  language ="javascript" > dot.gif
  6ExpandedSubBlockStart.gifContractedSubBlock.gif/**//****************
  7InBlock.gif
  8InBlock.gif* 由于字数限制,请下载附件看使用说明.
  9InBlock.gif*******如果您使用本日历控件 请保留该信息 谢谢! ***********   
 10InBlock.gif* http://2lin.net
 11InBlock.gif* Email:caoailin@gmail.com 
 12InBlock.gif* QQ:38062022 
 13InBlock.gif* Creation date: 2006-11-22 
 14ExpandedSubBlockEnd.gif******************/

 15InBlock.gif
 16InBlock.giffunction Calendar(objName)  
 17ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{        
 18ExpandedSubBlockStart.gifContractedSubBlock.gifthis.style = dot.gif{
 19InBlock.gif
 20InBlock.gifborderColor               : "#909eff"//边框颜色
 21InBlock.gifheaderBackColor            : "#909EFF"//表头背景颜色
 22InBlock.gifheaderFontColor            : "#ffffff"//表头字体颜色
 23InBlock.gifbodyBarBackColor          : "#f4f4f4"//日历标题背景色
 24InBlock.gifbodyBarFontColor          : "#000000"//日历标题字体色
 25InBlock.gifbodyBackColor             : "#ffffff"//日历背景色
 26InBlock.gifbodyFontColor            : "#000000"//日历字体色 
 27InBlock.gifbodyHolidayFontColor     : "#ff0000"//假日字体色
 28InBlock.gifwatermarkColor             : "#d4d4d4",  //背景水印色
 29InBlock.gifmoreDayColor             : "#cccccc" 
 30InBlock.gif
 31ExpandedSubBlockEnd.gif}
;
 32InBlock.gif
 33InBlock.gifthis.showMoreDay = false//是否显示上月和下月的日期
 34InBlock.gif
 35InBlock.gifthis.Obj = objName;        
 36InBlock.gifthis.date = null;
 37InBlock.gif
 38InBlock.gifthis.mouseOffset = null;
 39InBlock.gifthis.dateInput = null;
 40InBlock.gifthis.timer = null;    
 41InBlock.gif
 42ExpandedSubBlockEnd.gif}
;
 43InBlock.gif
 44InBlock.gifCalendar.prototype.toString = function()
 45ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{   
 46InBlock.gifvar str = this.getStyle();
 47InBlock.gifstr += '<div Author="alin" class="calendar" style="display:none;" onselectstart="return false" oncontextmenu="return false" id="Calendar">\n';
 48InBlock.gifstr += '<div Author="alin" class="cdrWatermark" id="cdrWatermark"></div><div id="cdrBody" style="position:absolute;left:0px;top:0px;z-index:2;width:140px;">';
 49InBlock.gifstr += this.getHeader();
 50InBlock.gifstr += this.getBody();   
 51InBlock.gifstr += '</div><div Author="alin" id="cdrMenu" style="position:absolute;left:0px;top:0px;z-index:3;display:none;"  onmouseover="' + this.Obj + '.showMenu(null);" onmouseout="' + this.Obj + '.hideMenu();"></div></div>';
 52InBlock.gifreturn str;
 53ExpandedSubBlockEnd.gif}
;
 54InBlock.gif
 55InBlock.gifCalendar.prototype.getStyle = function()
 56ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
 57InBlock.gifvar str = '<style type="text/css">\n';
 58ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.calendardot.gif{position:absolute;width:140px!important;width /**//**/:142px;height:184px!important;height /**//**/:174px;background-color:'+this.style.bodyBackColor+';border:1px solid ' + this.style.borderColor + ';left:0px;top:0px;z-index:9999;}\n';
 59ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.cdrHeaderdot.gif{background-color:'+ this.style.headerBackColor +';width:140px;height:22px;font-size:12px;color:'+this.style.headerFontColor+';}\n';
 60ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.cdrWatermarkdot.gif{position:absolute;left:0px;top:55px;width:140px;font-family: Arial Black;font-size:50px;color:'+this.style.watermarkColor+';z-index:1;text-align:center;}\n';
 61ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.cdrBodyBardot.gif{background-color:' + this.style.bodyBarBackColor + ';font-size:12px;color:' + this.style.bodyBarFontColor + ';width:140px;height:20px;}\n';
 62ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.cdrBodydot.gif{width:140px;height:122px!important; height /**//**/:110px;font-size:12px;cursor:pointer;color:' + this.style.bodyFontColor + ';}\n';
 63ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.dayOverdot.gif{height:16px;padding:0px;border:1px solid black;background-color:#f4f4f4;}\n';
 64ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.dayOutdot.gif{padding:1px;border:none;height:16px;}\n';
 65ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.menuOverdot.gif{background-color:'+this.style.headerBackColor+';color:'+this.style.headerFontColor+';font-size:12px;}\n';
 66ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.headerOverdot.gif{border:1px solid black;background-color:#f4f4f4;color:black;cursor:default;}\n';
 67ExpandedSubBlockStart.gifContractedSubBlock.gifstr += '.cdrMenudot.gif{font-size:12px;border:1px solid #000000;background-color:#ffffff;cursor:default;width:100%}\n';
 68ExpandedSubBlockStart.gifContractedSubBlock.gifstr += 'html>body #Calendardot.gif{width:142px;174px;}';
 69InBlock.gifstr += '</style>\n';    
 70InBlock.gifreturn str;
 71InBlock.gif
 72ExpandedSubBlockEnd.gif}
;
 73InBlock.gif
 74InBlock.gifCalendar.prototype.getHeader = function()
 75ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
 76InBlock.gifvar str = '<table Author="alin" class="cdrHeader" cellSpacing="2" cellPadding="0"><tr Author="alin" align="center">\n';
 77InBlock.gifstr += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="previousYear" title="上一年份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeYear(false);"><<</td>\n';
 78InBlock.gifstr += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="previousMonth" title="上一月份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeMonth(false);"><</td>\n';
 79InBlock.gifstr += '<td Author="alin" onmouseover="this.className=\'headerOver\'" id="currentYear" style="width:50px;" onclick="' + this.Obj + '.showMenu(true);" onmouseout="' + this.Obj + '.hideMenu();this.className=\'\';">0</td>\n';
 80InBlock.gifstr += '<td Author="alin" onmouseover="this.className=\'headerOver\'" id="currentMonth" onclick="' + this.Obj + '.showMenu(false);" onmouseout="' + this.Obj + '.hideMenu();this.className=\'\';">0</td>\n';
 81InBlock.gifstr += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="nextMonth" title="下一月份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeMonth(true);">></td>\n';
 82InBlock.gifstr += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="nextYear" title="下一年份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeYear(true);">>></td></tr>\n';
 83InBlock.gifstr += '</table>\n';
 84InBlock.gifreturn str;
 85ExpandedSubBlockEnd.gif}
;
 86InBlock.gif
 87InBlock.gifCalendar.prototype.getBody = function()
 88ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
 89InBlock.gifvar n = 0;
 90InBlock.gifvar str = this.getBodyBar();
 91InBlock.gifstr += '<table Author="alin" class="cdrBody" cellSpacing="2" cellPadding="0">\n';   
 92InBlock.giffor(i = 0; i < 6; i++)
 93ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{      
 94InBlock.gifstr += '<tr Author="alin" align="center">';
 95InBlock.giffor(j = 0; j < 7; j++)
 96ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
 97InBlock.gifstr += '<td Author="alin" class="dayOut" id="cdrDay'+(n++)+'" width="13%"></td>\n';
 98ExpandedSubBlockEnd.gif}

 99InBlock.gifstr += '</tr>';
100ExpandedSubBlockEnd.gif}

101InBlock.gifstr += '</table>\n';
102InBlock.gifstr += '<table Author="alin" class="cdrBodyBar" cellSpacing="2" cellPadding="0"><tr align="center" Author="alin"><td Author="alin" style="cursor:pointer;" onclick="'+this.Obj+'.getToday();">今天:'+new Date().toFormatString("yyyy年mm月dd日")+'</td></tr></table>\n';
103InBlock.gifreturn str;
104ExpandedSubBlockEnd.gif}
;
105InBlock.gif
106InBlock.gifCalendar.prototype.getBodyBar = function()
107ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
108InBlock.gifvar str = '<table Author="alin_bar" id="cdrBodyBar" class="cdrBodyBar" style="cursor:move;" cellSpacing="2" cellPadding="0"><tr Author="alin_bar" align="center">\n';
109InBlock.gifvar day = new Array('日','一','二','三','四','五','六');
110InBlock.giffor(i = 0; i < 7; i++)
111ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
112InBlock.gifstr += '<td Author="alin_bar">+ day[i] + '</td>\n';     
113ExpandedSubBlockEnd.gif}

114InBlock.gifstr += '</tr></table>';
115InBlock.gifreturn str;  
116ExpandedSubBlockEnd.gif}

117InBlock.gif
118InBlock.gifCalendar.prototype.getYearMenu = function(year)
119ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
120InBlock.gif
121InBlock.gifvar str = '<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0">\n';
122InBlock.giffor(i = 0; i < 10; i++)
123ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{      
124InBlock.gifvar _year = year + i;
125InBlock.gifvar _date = new Date(_year,this.date.getMonth(),this.date.getDate());
126InBlock.gif
127InBlock.gifstr += '<tr Author="alin" align="center"><td Author="alin" width="13%" height="16" ';
128InBlock.gifif(this.date.getFullYear() != _year)
129ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
130InBlock.gifstr += 'onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" ';
131ExpandedSubBlockEnd.gif}

132InBlock.gifelse
133ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
134InBlock.gifstr += 'class="menuOver"';
135ExpandedSubBlockEnd.gif}

136InBlock.gifstr += 'onclick="' + this.Obj + '.bindDate(\'' + _date.toFormatString("-") + '\')">+ _year + '年</td>\n';        
137InBlock.gifstr += '</tr>';
138ExpandedSubBlockEnd.gif}

139InBlock.gif
140InBlock.gifstr += '<tr Author="alin" align="center"><td Author="alin"><table Author="alin" style="font-size:12px;width:100%;" cellSpacing="0" cellPadding="0">\n';
141InBlock.gifstr += '<tr Author="alin" align="center"><td Author="alin" onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" onclick="'+this.Obj+'.getYearMenu('+ (year - 10) + ')"><<</td>\n';
142InBlock.gifstr += '<td Author="alin" onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" onclick="'+this.Obj+'.getYearMenu('+ (year + 10) +')">>></td><tr>\n';
143InBlock.gifstr += '</table></td></tr>\n';
144InBlock.gifstr += '</table>';
145InBlock.gif
146InBlock.gifvar _menu = getObjById("cdrMenu");
147InBlock.gif_menu.innerHTML = str;
148InBlock.gif
149ExpandedSubBlockEnd.gif}
;
150InBlock.gif
151InBlock.gifCalendar.prototype.getMonthMenu = function()
152ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
153InBlock.gif
154InBlock.gifvar str = '<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0">\n';
155InBlock.giffor(i = 1; i <= 12; i++)
156ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{   
157InBlock.gifvar _date = new Date(this.date.getFullYear(),i-1,this.date.getDate());        
158InBlock.gif
159InBlock.gifstr += '</tr><tr Author="alin" align="center"><td Author="alin" height="16" ';
160InBlock.gifif(this.date.getMonth() + 1 != i)
161ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
162InBlock.gifstr += 'onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" ';
163ExpandedSubBlockEnd.gif}

164InBlock.gifelse
165ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
166InBlock.gifstr += 'class="menuOver"';
167ExpandedSubBlockEnd.gif}

168InBlock.gifstr += 'onclick="' + this.Obj + '.bindDate(\'' + _date.toFormatString("-") + '\')">'+i+'月</td></tr>\n';
169ExpandedSubBlockEnd.gif}

170InBlock.gifstr += '</table>';
171InBlock.gif
172InBlock.gifvar _menu = getObjById("cdrMenu");
173InBlock.gif_menu.innerHTML = str;   
174ExpandedSubBlockEnd.gif}
;
175InBlock.gif
176InBlock.gifCalendar.prototype.show = function()
177ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
178InBlock.gifif (arguments.length >  3  || arguments.length == 0)
179ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
180InBlock.gifalert("对不起!传入参数不对!" );
181InBlock.gifreturn;
182ExpandedSubBlockEnd.gif}
   
183InBlock.gif
184InBlock.gifvar _date = null;
185InBlock.gifvar _evObj = null;
186InBlock.gifvar _initValue = null  
187InBlock.gif
188InBlock.giffor(i = 0; i < arguments.length; i++)
189ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
190InBlock.gifif(typeof(arguments[i]) == "object" && arguments[i].type == "text")
191ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{_date = arguments[i];}
192InBlock.gifelse if(typeof(arguments[i]) == "object")
193ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{_evObj = arguments[i];}
194InBlock.gifelse if(typeof(arguments[i]) == "string")
195ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{_initValue = arguments[i];}  
196ExpandedSubBlockEnd.gif}

197InBlock.gif_evObj = _evObj || _date;
198InBlock.gifinputObj = _date;
199InBlock.giftargetObj = _evObj
200InBlock.gif
201ExpandedSubBlockStart.gifContractedSubBlock.gifif(!_date)dot.gif{alert("传入参数错误!"); return;}
202InBlock.gif
203InBlock.gifthis.dateInput = _date;
204InBlock.gif
205InBlock.gif_date = _date.value;
206InBlock.gif
207InBlock.gifif(_date == "" && _initValue) _date = _initValue;   
208InBlock.gif
209InBlock.gifthis.bindDate(_date);        
210InBlock.gif
211InBlock.gifvar _target = getPosition(_evObj);   
212InBlock.gifvar _obj = getObjById("Calendar");
213InBlock.gif_obj.style.display = ""
214InBlock.gif
215InBlock.gif
216InBlock.gif_obj.style.left = _target.x + 'px';
217InBlock.gifif((document.body.clientHeight - (_target.y + _evObj.clientHeight)) >= _obj.clientHeight)
218ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{        
219InBlock.gif_obj.style.top = (_target.y + _evObj.clientHeight) + 'px';
220ExpandedSubBlockEnd.gif}

221InBlock.gifelse
222ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{      
223InBlock.gif_obj.style.top = (_target.y - _obj.clientHeight) + 'px';
224ExpandedSubBlockEnd.gif}

225InBlock.gif
226ExpandedSubBlockEnd.gif}
;
227InBlock.gif
228InBlock.gifCalendar.prototype.hide = function()
229ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
230InBlock.gifvar obj = getObjById("Calendar");
231InBlock.gifobj.style.display = "none";   
232ExpandedSubBlockEnd.gif}
;
233InBlock.gif
234InBlock.gifCalendar.prototype.bindDate = function(date)
235ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
236InBlock.gif
237InBlock.gifvar _monthDays = new Array(31,30,31,30,31,30,31,31,30,31,30,31);    
238InBlock.gifvar _arr = date.split('-');        
239InBlock.gifvar _date = new Date(_arr[0],_arr[1]-1,_arr[2]);    
240InBlock.gifif(isNaN(_date)) _date = new Date();    
241InBlock.gifthis.date = _date;
242InBlock.gifthis.bindHeader();    
243InBlock.gif
244InBlock.gifvar _year = _date.getFullYear();
245InBlock.gifvar _month = _date.getMonth();
246InBlock.gifvar _day = 1;    
247InBlock.gif
248InBlock.gifvar _startDay = new Date(_year,_month,1).getDay();
249InBlock.gifvar _previYear = _month == 0 ? _year - 1 : _year;
250InBlock.gifvar _previMonth = _month == 0 ? 11 : _month - 1;
251InBlock.gifvar _previDay = _monthDays[_previMonth];
252InBlock.gifif (_previMonth == 1) _previDay =((_previYear%4==0)&&(_previYear%100!=0)||(_previYear%400==0))?29:28;    
253InBlock.gif_previDay -= _startDay - 1;
254InBlock.gifvar _nextDay = 1;
255InBlock.gif
256InBlock.gif_monthDays[1= ((_year%4==0)&&(_year%100!=0)||(_year%400==0))?29:28;
257InBlock.gif
258InBlock.giffor(i = 0; i < 40; i++)
259ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{    
260InBlock.gifvar _dayElement = getObjById("cdrDay" + i);
261InBlock.gif
262InBlock.gif_dayElement.onmouseover = Function(this.Obj + ".onMouseOver(this)");
263InBlock.gif_dayElement.onmouseout = Function(this.Obj + ".onMouseOut(this)");
264InBlock.gif_dayElement.onclick = Function(this.Obj + ".onClick(this)");
265InBlock.gifthis.onMouseOut(_dayElement);             
266InBlock.gif_dayElement.style.color = "";
267InBlock.gif
268InBlock.gifif(i < _startDay)
269ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
270InBlock.gif//获取上一个月的日期
271InBlock.gifif(this.showMoreDay)
272ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
273InBlock.gifvar _previDate = new Date(_year,_month - 1,_previDay);
274InBlock.gif_dayElement.innerHTML = _previDay;
275InBlock.gif_dayElement.title = _previDate.toFormatString("yyyy年mm月dd日");
276InBlock.gif_dayElement.value = _previDate.toFormatString("-");    
277InBlock.gif_dayElement.style.color = this.style.moreDayColor;    
278InBlock.gif
279InBlock.gif_previDay++;
280InBlock.gif
281ExpandedSubBlockEnd.gif}
else
282ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
283InBlock.gif_dayElement.innerHTML = "";
284InBlock.gif_dayElement.title = "";
285ExpandedSubBlockEnd.gif}

286InBlock.gif
287ExpandedSubBlockEnd.gif}

288InBlock.gifelse if(_day > _monthDays[_month])
289ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
290InBlock.gif//获取下个月的日期
291InBlock.gifif(this.showMoreDay)
292ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
293InBlock.gifvar _nextDate = new Date(_year,_month + 1,_nextDay);
294InBlock.gif_dayElement.innerHTML = _nextDay;
295InBlock.gif_dayElement.title = _nextDate.toFormatString("yyyy年mm月dd日");
296InBlock.gif_dayElement.value = _nextDate.toFormatString("-");
297InBlock.gif_dayElement.style.color = this.style.moreDayColor;    
298InBlock.gif
299InBlock.gif_nextDay++;               
300ExpandedSubBlockEnd.gif}
else
301ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
302InBlock.gif_dayElement.innerHTML = "";
303InBlock.gif_dayElement.title = "";
304ExpandedSubBlockEnd.gif}

305ExpandedSubBlockEnd.gif}

306InBlock.gifelse if(i >= new Date(_year,_month,1).getDay() && _day <= _monthDays[_month])
307ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
308InBlock.gif//获取本月日期
309InBlock.gif_dayElement.innerHTML = _day;
310InBlock.gif
311InBlock.gifif(_day == _date.getDate())
312ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
313InBlock.gifthis.onMouseOver(_dayElement);
314InBlock.gif_dayElement.onmouseover = Function("");   
315InBlock.gif_dayElement.onmouseout = Function("");                                       
316ExpandedSubBlockEnd.gif}

317InBlock.gif
318InBlock.gif
319InBlock.gifif(this.isHoliday(_year,_month,_day))
320ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
321InBlock.gif_dayElement.style.color = this.style.bodyHolidayFontColor;              
322ExpandedSubBlockEnd.gif}

323InBlock.gifvar _curDate = new Date(_year, _month, _day);
324InBlock.gif_dayElement.title =  _curDate.toFormatString("yyyy年mm月dd日");
325InBlock.gif_dayElement.value = _curDate.toFormatString("-");
326InBlock.gif
327InBlock.gif_day++;
328InBlock.gif
329ExpandedSubBlockEnd.gif}

330InBlock.gifelse
331ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
332InBlock.gif_dayElement.innerHTML = "";
333InBlock.gif_dayElement.title = "";
334ExpandedSubBlockEnd.gif}
    
335InBlock.gif
336ExpandedSubBlockEnd.gif}

337InBlock.gif
338InBlock.gifvar _menu = getObjById("cdrMenu");
339InBlock.gif_menu.style.display = "none";    
340InBlock.gif
341ExpandedSubBlockEnd.gif}
;
342InBlock.gif
343InBlock.gif
344InBlock.gifCalendar.prototype.bindHeader = function()
345ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
346InBlock.gifvar _curYear = getObjById("currentYear");
347InBlock.gifvar _curMonth = getObjById("currentMonth");
348InBlock.gifvar _watermark = getObjById("cdrWatermark");
349InBlock.gif
350InBlock.gif_curYear.innerHTML = this.date.toFormatString("yyyy年");
351InBlock.gif_curMonth.innerHTML =  this.date.toFormatString("mm月");
352InBlock.gif_watermark.innerHTML = this.date.getFullYear();     
353InBlock.gif
354ExpandedSubBlockEnd.gif}
;    
355InBlock.gif
356InBlock.gifCalendar.prototype.getToday = function()
357ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
358InBlock.gifvar _date = new Date();
359InBlock.gifthis.bindDate(_date.toFormatString("-"));
360ExpandedSubBlockEnd.gif}
;    
361InBlock.gif
362InBlock.gifCalendar.prototype.isHoliday = function(year,month,date)
363ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
364InBlock.gifvar _date = new Date(year,month,date);
365InBlock.gifreturn (_date.getDay() == 6 || _date.getDay() == 0);
366ExpandedSubBlockEnd.gif}
;
367InBlock.gif
368InBlock.gifCalendar.prototype.onMouseOver = function(obj)
369ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
370InBlock.gifobj.className = "dayOver";
371ExpandedSubBlockEnd.gif}
;
372InBlock.gif
373InBlock.gif
374InBlock.gifCalendar.prototype.onMouseOut = function(obj)
375ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
376InBlock.gifobj.className = "dayOut";
377ExpandedSubBlockEnd.gif}
;    
378InBlock.gif
379InBlock.gifCalendar.prototype.onClick = function(obj)
380ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{  
381InBlock.gifif(obj.innerHTML != "")  this.dateInput.value = obj.value;
382InBlock.gifthis.hide();
383ExpandedSubBlockEnd.gif}
;
384InBlock.gif
385InBlock.gifCalendar.prototype.onChangeYear = function(isnext)
386ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
387InBlock.gifvar _year = this.date.getFullYear();
388InBlock.gifvar _month = this.date.getMonth() + 1;
389InBlock.gifvar _date = this.date.getDate();
390InBlock.gif
391InBlock.gifif(_year > 999 && _year <10000)
392ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
393ExpandedSubBlockStart.gifContractedSubBlock.gifif(isnext)dot.gif{_year++;}elsedot.gif{ _year --;}
394ExpandedSubBlockEnd.gif}

395InBlock.gifelse
396ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
397InBlock.gifalert("年份超出范围(1000-9999)!");
398ExpandedSubBlockEnd.gif}

399InBlock.gifthis.bindDate(_year + '-+ _month + '-+ _date);
400ExpandedSubBlockEnd.gif}
;
401InBlock.gif
402InBlock.gifCalendar.prototype.onChangeMonth = function(isnext)
403ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
404InBlock.gifvar _year = this.date.getFullYear();
405InBlock.gifvar _month = this.date.getMonth() + 1;
406InBlock.gifvar _date = this.date.getDate();
407InBlock.gif
408ExpandedSubBlockStart.gifContractedSubBlock.gifif(isnext)dot.gif{ _month ++;} else dot.gif{_month--;}
409InBlock.gif
410InBlock.gifif(_year > 999 && _year <10000)
411ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif
412ExpandedSubBlockStart.gifContractedSubBlock.gifif(_month < 1dot.gif{_month = 12; _year--;}
413ExpandedSubBlockStart.gifContractedSubBlock.gifif(_month > 12dot.gif{_month = 1; _year++;}
414ExpandedSubBlockEnd.gif}

415InBlock.gifelse
416ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
417InBlock.gifalert("年份超出范围(1000-9999)!");
418ExpandedSubBlockEnd.gif}
  
419InBlock.gif
420InBlock.gifthis.bindDate(_year + '-+ _month + '-+ _date);
421ExpandedSubBlockEnd.gif}
;
422InBlock.gif
423InBlock.gifCalendar.prototype.showMenu = function(isyear)
424ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
425InBlock.gifvar _menu = getObjById("cdrMenu");
426InBlock.gif
427InBlock.gifif(isyear != null)
428ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{    
429InBlock.gifvar _obj = (isyear)? getObjById("currentYear") : getObjById("currentMonth");
430InBlock.gif
431InBlock.gifif(isyear)
432ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
433InBlock.gifthis.getYearMenu(this.date.getFullYear() - 5);       
434ExpandedSubBlockEnd.gif}

435InBlock.gifelse
436ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
437InBlock.gifthis.getMonthMenu();       
438ExpandedSubBlockEnd.gif}

439InBlock.gif
440InBlock.gif_menu.style.top = (_obj.offsetTop + _obj.offsetHeight) + 'px';
441InBlock.gif_menu.style.left = _obj.offsetLeft + 'px';    
442InBlock.gif_menu.style.width = _obj.offsetWidth + 'px';
443InBlock.gif
444ExpandedSubBlockEnd.gif}

445InBlock.gif
446InBlock.gifif (this.timer != null) clearTimeout(this.timer);
447InBlock.gif
448InBlock.gif_menu.style.display="";
449InBlock.gif
450ExpandedSubBlockEnd.gif}

451InBlock.gifCalendar.prototype.hideMenu = function()
452ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
453InBlock.gifvar _obj = getObjById("cdrMenu");
454ExpandedSubBlockStart.gifContractedSubBlock.gifthis.timer = window.setTimeout(function()dot.gif{_obj.style.display='none';},500);    
455ExpandedSubBlockEnd.gif}

456InBlock.gif
457InBlock.gifNumber.prototype.NaN0 = function()
458ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
459InBlock.gifreturn isNaN(this? 0 : this;
460ExpandedSubBlockEnd.gif}

461InBlock.gif
462InBlock.gifDate.prototype.toFormatString = function(fs)
463ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
464InBlock.gifif(fs.length == 1)
465ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif
466InBlock.gifreturn this.getFullYear() + fs + (this.getMonth() + 1+ fs + this.getDate(); 
467ExpandedSubBlockEnd.gif}

468InBlock.giffs = fs.replace("yyyy",this.getFullYear());
469InBlock.giffs = fs.replace("mm",(this.getMonth() + 1));
470InBlock.giffs = fs.replace("dd",this.getDate());
471InBlock.gifreturn fs;
472ExpandedSubBlockEnd.gif}

473InBlock.gif
474ExpandedSubBlockStart.gifContractedSubBlock.gif/**//************公用方法及变量**************/
475InBlock.gifvar inputObj = null
476InBlock.gifvar targetObj = null;    
477InBlock.gifvar dragObj = null
478InBlock.gifvar mouseOffset = null
479InBlock.gif
480InBlock.giffunction getObjById(obj)
481ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
482InBlock.gifif(document.getElementById)
483ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
484InBlock.gifreturn document.getElementById(obj);
485ExpandedSubBlockEnd.gif}

486InBlock.gifelse
487ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
488InBlock.gifalert("浏览器不支持!");
489ExpandedSubBlockEnd.gif}

490ExpandedSubBlockEnd.gif}

491InBlock.gif
492InBlock.giffunction mouseCoords(ev)
493ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
494ExpandedSubBlockStart.gifContractedSubBlock.gifif(ev.pageX || ev.pageY)dot.gif{
495ExpandedSubBlockStart.gifContractedSubBlock.gifreturn dot.gif{x:ev.pageX, y:ev.pageY};
496ExpandedSubBlockEnd.gif}

497ExpandedSubBlockStart.gifContractedSubBlock.gifreturn dot.gif{
498InBlock.gifx:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
499InBlock.gify:ev.clientY + document.body.scrollTop  - document.body.clientTop
500ExpandedSubBlockEnd.gif}
;
501ExpandedSubBlockEnd.gif}

502InBlock.gif
503InBlock.gif
504InBlock.giffunction getPosition(e)
505ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
506InBlock.gifvar left = 0;
507InBlock.gifvar top  = 0;
508ExpandedSubBlockStart.gifContractedSubBlock.gifwhile (e.offsetParent)dot.gif{
509InBlock.gifleft += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
510InBlock.giftop  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
511InBlock.gife     = e.offsetParent;
512ExpandedSubBlockEnd.gif}

513InBlock.gif
514InBlock.gifleft += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
515InBlock.giftop  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
516InBlock.gif
517ExpandedSubBlockStart.gifContractedSubBlock.gifreturn dot.gif{x:left, y:top};
518ExpandedSubBlockEnd.gif}

519InBlock.giffunction getMouseOffset(target, ev)
520ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
521InBlock.gifev = ev || window.event;
522InBlock.gifvar docPos    = getPosition(target);
523InBlock.gifvar mousePos  = mouseCoords(ev);
524ExpandedSubBlockStart.gifContractedSubBlock.gifreturn dot.gif{x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
525ExpandedSubBlockEnd.gif}

526InBlock.gif
527ExpandedSubBlockStart.gifContractedSubBlock.giffunction closeCalendar(evt)dot.gif{
528InBlock.gif
529InBlock.gifevt = evt || window.event; 
530InBlock.gifvar _target= evt.target || evt.srcElement; 
531InBlock.gif
532InBlock.gifif(!_target.getAttribute("Author"&&  _target != inputObj && _target != targetObj)
533ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
534InBlock.gifgetObjById("Calendar").style.display = "none";       
535ExpandedSubBlockEnd.gif}
  
536ExpandedSubBlockEnd.gif}

537InBlock.gif
538ExpandedSubBlockStart.gifContractedSubBlock.giffunction dragStart(evt)dot.gif{
539InBlock.gif
540InBlock.gifevt = evt || window.event;    
541InBlock.gifvar _target= evt.target || evt.srcElement;
542InBlock.gif
543InBlock.gifif(_target.getAttribute("Author"== "alin_bar"
544ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{       
545InBlock.gifdragObj = getObjById("Calendar");       
546InBlock.gifmouseOffset = getMouseOffset(dragObj, evt);     
547InBlock.gif
548ExpandedSubBlockEnd.gif}
   
549ExpandedSubBlockEnd.gif}

550InBlock.giffunction drag(evt)
551ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
552InBlock.gifevt =  evt || window.event;    
553InBlock.gifif(dragObj)
554ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{          
555InBlock.gifvar mousePos = mouseCoords(evt); 
556InBlock.gifdragObj.style.left = (mousePos.x - mouseOffset.x) + 'px';
557InBlock.gifdragObj.style.top  = (mousePos.y - mouseOffset.y) + 'px';      
558ExpandedSubBlockEnd.gif}

559ExpandedSubBlockEnd.gif}

560InBlock.gif//拖动结束
561InBlock.giffunction dragEnd(evt)
562ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
563InBlock.gifdragObj = null;    
564ExpandedSubBlockEnd.gif}

565ExpandedSubBlockStart.gifContractedSubBlock.gif/**//***********End 公用方法*********/
566InBlock.gifdocument.onclick = closeCalendar;
567InBlock.gifdocument.onmousedown = dragStart;
568InBlock.gifdocument.onmousemove = drag;
569InBlock.gifdocument.onmouseup = dragEnd;
570ExpandedSubBlockStart.gifContractedSubBlock.gif/**//*********结束**********/
571None.gif
</ script >
572 None.gif </ head >
573 None.gif < body >
574 None.gif < form  id ="Form1" >
575 ExpandedBlockStart.gifContractedBlock.gif < script > dot.gif
576InBlock.gifvar c = new Calendar("c");
577ExpandedBlockEnd.gifdocument.write(c);
578None.gif
</ script >
579 None.gif普通调用: < input  type ="text"  name ="txt"   onfocus ="c.showMoreDay = false;c.show(this,'1980-01-01');" />< input  type ="text"  name ="txt1"   onfocus ="c.showMoreDay = false;c.show('1981-01-01',this);" />< input  type ="text"  name ="txt2"   onfocus ="c.showMoreDay = false;c.show(this);" />< br  />< div  style ="height:300px" ></ div >  按钮调用: < input  type ="text"  name ="btntxt"  id ="btntxt"   />< input  name ="button"  value ="*"  id ="button"  type ="button"  onclick ="c.showMoreDay = true;c.show(getObjById('btntxt'),'1982-1-1',this)" />   < input  type ="text"  name ="btntxt1"  id ="btntxt1"   />< input  name ="button1"   value ="*"   id ="button1"  type ="button"  onclick ="c.showMoreDay = true;c.show(getObjById('btntxt1'),this,'1983-1-1')" />< br  />< br  />< br  />     < input  type ="text"  name ="btntxt3"  id ="btntxt3"   />< input  name ="button3"  value ="*"   id ="button3"  type ="button"  onclick ="c.showMoreDay = true;c.show(this,getObjById('btntxt3'))" /></ form ></ body >
580 None.gif </ html >

转载于:https://www.cnblogs.com/kunhony/archive/2007/05/31/766043.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值