⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webcalendar.js

📁 这是matlab的一个小程序
💻 JS
📖 第 1 页 / 共 2 页
字号:
	this.calendarToday = obj;
}

//年份下拉框绑定数据
Calendar.prototype.bindYear = function() {
	//var cy = this.form.calendarYear;
	var cy = this.calendarYear;
	cy.length = 0;
	for (var i = this.beginYear; i <= this.endYear; i++){
		cy.options[cy.length] = new Option(i + Calendar.language["year"][this.lang], i);
	}
}

//月份下拉框绑定数据
Calendar.prototype.bindMonth = function() {
	//var cm = this.form.calendarMonth;
	var cm = this.calendarMonth;
	cm.length = 0;
	for (var i = 0; i < 12; i++){
		cm.options[cm.length] = new Option(Calendar.language["months"][this.lang][i], i);
	}
}

//向前一月
Calendar.prototype.goPrevMonth = function(e){
	if (this.year == this.beginYear && this.month == 0){return;}
	this.month--;
	if (this.month == -1) {
		this.year--;
		this.month = 11;
	}
	this.date = new Date(this.year, this.month, 1);
	this.changeSelect();
	this.bindData();
}

//向后一月
Calendar.prototype.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);
	this.changeSelect();
	this.bindData();
}

//改变SELECT选中状态
Calendar.prototype.changeSelect = function() {
	var cy = this.calendarYear;
	var cm = this.calendarMonth;
	for (var i= 0; i < cy.length; i++){
		if (cy.options[i].value == this.date.getFullYear()){
			cy[i].selected = true;
			break;
		}
	}
	for (var i= 0; i < cm.length; i++){
		if (cm.options[i].value == this.date.getMonth()){
			cm[i].selected = true;
			break;
		}
	}
}

//更新年、月
Calendar.prototype.update = function (e){
	this.year  = e.calendarYear.options[e.calendarYear.selectedIndex].value;
	this.month = e.calendarMonth.options[e.calendarMonth.selectedIndex].value;
	this.date = new Date(this.year, this.month, 1);
	this.changeSelect();
	this.bindData();
}

//绑定数据到月视图
Calendar.prototype.bindData = function () {
	var calendar = this;
	var dateArray = this.getMonthViewArray(this.date.getYear(), this.date.getMonth());
	var tds = this.getElementById("calendarTable").getElementsByTagName("td");
	for(var i = 0; i < tds.length; i++) {
		//tds[i].style.color = calendar.colors["td_word_light"];
		tds[i].style.backgroundColor = calendar.colors["td_bg_out"];
		tds[i].onclick = function () {return;}
		tds[i].onmouseover = function () {return;}
		tds[i].onmouseout = function () {return;}
		if (i > dateArray.length - 1) break;
		tds[i].innerHTML = dateArray[i];
		if (dateArray[i] != "&nbsp;"){
			tds[i].onclick = function () {
				if (calendar.dateControl != null){
					calendar.dateControl.value = new Date(calendar.date.getFullYear(),
					calendar.date.getMonth(),
					this.innerHTML).format(calendar.dateFormatStyle);
				}
				calendar.hide();
			}
			tds[i].onmouseover = function () {
				this.style.backgroundColor = calendar.colors["td_bg_over"];
			}
			tds[i].onmouseout = function () {
				this.style.backgroundColor = calendar.colors["td_bg_out"];
			}
			if (new Date().format(calendar.dateFormatStyle) ==
			new Date(calendar.date.getFullYear(),
			calendar.date.getMonth(),
			dateArray[i]).format(calendar.dateFormatStyle)) {
				//tds[i].style.color = calendar.colors["cur_word"];
				tds[i].style.backgroundColor = calendar.colors["cur_bg"];
				tds[i].onmouseover = function () {
					this.style.backgroundColor = calendar.colors["td_bg_over"];
				}
				tds[i].onmouseout = function () {
					this.style.backgroundColor = calendar.colors["cur_bg"];
				}
				//continue;
			}//end if

			if (calendar.dateControl != null && calendar.dateControl.value == new Date(calendar.date.getFullYear(),
			calendar.date.getMonth(),
			dateArray[i]).format(calendar.dateFormatStyle)) {
				tds[i].style.backgroundColor = calendar.colors["sel_bg"];
				tds[i].onmouseover = function () {
					this.style.backgroundColor = calendar.colors["td_bg_over"];
				}
				tds[i].onmouseout = function () {
					this.style.backgroundColor = calendar.colors["sel_bg"];
				}
			}
		}
	}
}

//根据年、月得到月视图数据(数组形式)
Calendar.prototype.getMonthViewArray = function (y, m) {
	var mvArray = [];
	var dayOfFirstDay = new Date(y, m, 1).getDay();
	var daysOfMonth = new Date(y, m + 1, 0).getDate();
	for (var i = 0; i < 42; i++) {
		mvArray[i] = "&nbsp;";
	}
	for (var i = 0; i < daysOfMonth; i++){
		mvArray[i + dayOfFirstDay] = i + 1;
	}
	return mvArray;
}

//扩展 document.getElementById(id) 多浏览器兼容性 from meizz tree source
Calendar.prototype.getElementById = function(id){
	if (typeof(id) != "string" || id == "") return null;
	if (document.getElementById) return document.getElementById(id);
	if (document.all) return document.all(id);
	try {return eval(id);} catch(e){ return null;}
}

//扩展 object.getElementsByTagName(tagName)
Calendar.prototype.getElementsByTagName = function(object, tagName){
	if (document.getElementsByTagName) return document.getElementsByTagName(tagName);
	if (document.all) return document.all.tags(tagName);
}

//取得HTML控件绝对位置
Calendar.prototype.getAbsPoint = function (e){
	var x = e.offsetLeft;
	var y = e.offsetTop;
	while(e = e.offsetParent){
		x += e.offsetLeft;
		y += e.offsetTop;
	}
	return {"x": x, "y": y};
}

//显示日历
Calendar.prototype.show = function (dateObj, popControl) {
	if (dateObj == null){
		throw new Error("arguments[0] is necessary")
	}
	this.dateControl = dateObj;

	this.date = (dateObj.value.length > 0) ? new Date(dateObj.value.toDate(this.dateFormatStyle)) : new Date() ;//2006-12-03 寒羽枫添加 → 若为空则显示当前月份
	this.year = this.date.getFullYear();
	this.month = this.date.getMonth();
	this.changeSelect();
	this.bindData();
	//}
	if (popControl == null){
		popControl = dateObj;
	}
	var xy = this.getAbsPoint(popControl);
	this.panel.style.left = xy.x -25 + "px";
	this.panel.style.top = (xy.y + dateObj.offsetHeight) + "px";

	this.panel.style.display = "";
	this.container.style.display = "";

	dateObj.onblur = function(){calendar.onblur();}
	this.container.onmouseover = function(){isFocus=true;}
	this.container.onmouseout = function(){isFocus=false;}
}

//隐藏日历
Calendar.prototype.hide = function() {
	this.panel.style.display = "none";
	this.container.style.display = "none";
	isFocus=false;
}

//焦点转移时隐藏日历 → 由寒羽枫 2006-06-25 添加
Calendar.prototype.onblur = function() {
	if(!isFocus){this.hide();}
}

document.write('<div id="ContainerPanel" style="display:none"><div id="calendarPanel" style="position: absolute;display: none;z-index: 9999;');
document.write('background-color: #FFFFFF;border: 1px solid #CCCCCC;width:175px;font-size:12px;"></div>');
if(document.all)
{
	document.write('<iframe style="position:absolute;z-index:2000;width:expression(this.previousSibling.offsetWidth);');
	document.write('height:expression(this.previousSibling.offsetHeight);');
	document.write('left:expression(this.previousSibling.offsetLeft);top:expression(this.previousSibling.offsetTop);');
	document.write('display:expression(this.previousSibling.style.display);" scrolling="no" frameborder="no"></iframe>');
}
document.write('</div>');
-->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -