日历提示样式分为3类。 a. 当日 b.当年当月当日提示样式 c.当月当日提示样式 鼠标覆盖在有提示的日期上自动出现提示内容 4.。。。。。 主要分为2种用处。 1.提供一个 div 或其他 element 将该容器的 id 传给 Calendar。方法名为: show() 例: var cr = Calendar("div1"); cr.show( /*data - 该数组为可选项,如果传则有提示功能*/ ); 2.提供一个 input[type="text"] 的元素 将该元素的 id 传给 Calendar。方法名为: pop() 例: var cr = Calendar("input2"); cr.pop(); 其他的就不多说了。觉得好的话,就支持下。呵呵。 有什么问题或好的想法,请告诉我。谢谢 详细的用法和例子在压缩包里有。 演示地址 http://img.jb51.net/online/calendar/demo-1.html http://img.jb51.net/online/calendar/demo-2.html 打包下载地址 http://www.jb51.net/codes/12595.html 复制代码 代码如下: /* * Calendar * Language 0: Chinese, 1: English * 1.Put calendar into the element html use "show()" * 2.Pop-up calendar use "pop()" */
// Create End return caleElem; }; /* Get Month Data */ Calendar.prototype._getMonthViewArray = function( year, month ){ var monthArray = []; // From the beginning day of the week var beginDayOfWeek = new Date( year, month, 1).getDay();
// This month total days var daysOfMonth = new Date( year, month + 1, 0).getDate();
// 42: 7*6 matrix for( var i = 0; i < 42; i ++ ) monthArray[i] = " ";
return monthArray; }; /* Search the index of option in the select */ Calendar.prototype._getOptionIndex = function( selectObject, value ){ for( var j = 0; j < selectObject.options.length; j ++ ){ if( value == selectObject.options[j].value ) return j; } }; /* Bind year data into "Year select" */ Calendar.prototype._bindYearIntoSelect = function(){ var oYear = this.find( this.caleTop.sq_year_id ); var oYearLen = 0; for( var i = this.StartYear; i <= this.EndYear; i ++, oYearLen ++ ) oYear.options[oYearLen] = new Option( i , i ); }; /* Bind Month data into "Month select" */ Calendar.prototype._bindMonthIntoSelect = function(){ var oMonth = this.find( this.caleTop.sq_month_id ); var oMonthLen = 0; for( var i = 0; i < 12; i ++, oMonthLen ++ ) oMonth.options[oMonthLen] = new Option( i + 1 , i + 1 ); }; /* Bind data */ Calendar.prototype._bindAllData = function( curYear, curMonth ){ var cr = this; // Bind default Data into "select:Year" this._bindYearIntoSelect();
// Bind default Data into "select:Month" this._bindMonthIntoSelect();
// Change the "select:Year" and "select:Month" value this.changeSelectValue( curYear, curMonth );
// Bind default data into "current day view and current week view" this.find( this.caleTop.week_view_id ).innerHTML = Calendar.lang["weeks"][this.Language][this.Week]; this.find( this.caleTop.today_view_id ).innerHTML = this.Today;
// Get days and bind into "CalendarMain" // Add current day class and mouse event var daysOfMonthArray = this._getMonthViewArray( curYear, curMonth ); var spans = this.find( this.daysContainer_id, "span" ); var curYMD = this.Year + "" + ( this.Month + 1 ) + "" + this.Today; var selectYear = this.find( this.caleTop.sq_year_id ).value; var selectMonth = this.find( this.caleTop.sq_month_id ).value; for( var i = 0; i < spans.length; i ++ ){ spans[i].innerHTML = daysOfMonthArray[i]; var selectYMD = selectYear + "" + selectMonth + "" + spans[i].innerHTML; if( curYMD == selectYMD ) spans[i].className = this.curDayClass; else spans[i].className = ""; } // If not some days has pop message if( this.msgStore != "" ) this._initPopMsg( this.msgStore ); } /* Bind event */ Calendar.prototype._bindAllEvent = function(){ var cr = this; // "toPrevMonth, toNextMonth, backToday, today view" event this.find( this.caleTop.prev_month_id ).onclick = function(){ cr.goPrevOrNextMonth(this); }; this.find( this.caleTop.next_month_id ).onclick = function(){ cr.goPrevOrNextMonth(this); }; this.find( this.caleTop.back_today_id ).onclick = function(){ cr.backToday(); }; this.find( this.caleTop.today_view_id ).onclick = function(){ cr.backToday(); };
for( var i = 0; i < selectArray.length; i ++ ){ var selectObject = this.find( selectArray[i] ); // Get the return index var index = this._getOptionIndex( selectObject, ymArray[i] ); // Reset the "year", "month" select and link value selectObject.options[index].selected = "selected";