📄 datetime.js
字号:
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;//2006-12-01 由寒羽枫修改
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.hours,this.minutes,this.seconds);
this.changeSelect();
this.bindData();
}
//改变SELECT选中状态
Calendar.prototype.changeSelect = function() {
//var cy = this.form.calendarYear;
//var cm = this.form.calendarMonth;
var cy = this.calendarYear;//2006-12-01 由寒羽枫修改
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.form.calendarYear.options[e.form.calendarYear.selectedIndex].value;
//this.month = e.form.calendarMonth.options[e.form.calendarMonth.selectedIndex].value;
this.year = e.calendarYear.options[e.calendarYear.selectedIndex].value;//2006-12-01 由寒羽枫修改
this.month = e.calendarMonth.options[e.calendarMonth.selectedIndex].value;
this.date = new Date(this.year, this.month, 1,this.hours,this.minutes,this.seconds);
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] != " "){
tds[i].onclick = function () {
if (calendar.dateControl != null){
// calendar.dateControl.value = new Date(calendar.date.getFullYear(), calendar.date.getMonth(),this.innerHTML).format(calendar.dateFormatStyle);
//以下 mazq 2007-4-4 添加和修改
this.hours = c_hours.value;
this.minutes = c_minutes.value;
this.seconds = c_seconds.value;
this.date = new Date(calendar.date.getFullYear(), calendar.date.getMonth(),this.innerHTML,this.hours,this.minutes,this.seconds);
calendar.dateControl.value = this.date.format(calendar.dateFormatStyle);
//以上 mazq 2007-4-4 添加和修改
}
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; //若不想当天单元格的背景被下面的覆盖,请取消注释 → 2006-12-03 寒羽枫添加
}//end if
//设置已被选择的日期单元格背影色 2006-12-03 寒羽枫添加
// if (calendar.dateControl != null && calendar.dateControl.value == new Date(calendar.date.getFullYear(),
// calendar.date.getMonth(),
// dateArray[i]).format(calendar.dateFormatStyle)) {
//mazq 修改 在带有时间的条件下,设置已被选择的日期单元格 2007-4-5
if (calendar.dateControl != null && calendar.dateControl.value == new Date(calendar.date.getFullYear(),
calendar.date.getMonth(),
dateArray[i], c_hours.value, c_minutes.value, c_seconds.value).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] = " ";
}
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;
//if (dateObj.value.length > 0){
//this.date = new Date(dateObj.value.toDate());
//this.date = new Date(dateObj.value.toDate(this.dateFormatStyle));//由寒羽枫修改,带入用户指定的 style
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();
//以下 mazq 2007-4-4 添加
this.hours = this.date.getHours();
this.minutes = this.date.getMinutes();
this.seconds = this.date.getSeconds();
c_hours.value = this.hours;
c_minutes.value = this.minutes;
c_seconds.value = this.seconds;
//以上 mazq 2007-4-4 添加
//}
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";
//由寒羽枫 2006-06-25 修改 → 把 visibility 变为 display,并添加失去焦点的事件
//this.setDisplayStyle("select", "hidden");
//this.panel.style.visibility = "visible";
//this.container.style.visibility = "visible";
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.setDisplayStyle("select", "visible");
//this.panel.style.visibility = "hidden";
//this.container.style.visibility = "hidden";
this.panel.style.display = "none";
this.container.style.display = "none";
isFocus=false;
}
//焦点转移时隐藏日历 → 由寒羽枫 2006-06-25 添加
Calendar.prototype.onblur = function() {
if(!isFocus){this.hide();}
}
//以下由寒羽枫 2006-06-25 修改 → 用<iframe> 遮住 IE 的下拉框
/**//**//**//*
//设置控件显示或隐藏
Calendar.prototype.setDisplayStyle = function(tagName, style) {
var tags = this.getElementsByTagName(null, tagName)
for(var i = 0; i < tags.length; i++) {
if (tagName.toLowerCase() == "select" &&
(tags[i].name == "calendarYear" ||
tags[i].name == "calendarMonth")){
continue;
}
//tags[i].style.visibility = style;
tags[i].style.display = style;
}
}
*/
//document.write('<div id="ContainerPanel" style="visibility:hidden"><div id="calendarPanel" style="position: absolute;visibility: hidden;z-index: 9999;');
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:10px;"></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>');
//var calendar = new Calendar(); //此句被 寒羽枫注释,否则 IE 将报错
//调用calendar.show(dateControl, popControl);
//以下 mazq 2007-4-4 添加
Calendar.prototype.play = function()
{
//this.timer = setInterval("calendarTime.playback()",1000);
}
Calendar.prototype.formatTime = function(sTime)
{
sTime = ("0"+sTime);
return sTime.substr(sTime.length-2);
}
Calendar.prototype.playback = function()
{
var objDate = new Date();
var arrDate = [objDate.getHours(),objDate.getMinutes(),objDate.getSeconds()];
var objMinute = this.getElementById("txtcalendarTime");
for (var i=0;i<objMinute.length;i++)
{
objMinute[i].value = this.formatTime(arrDate[i])
}
}
Calendar.prototype.prevent = function(obj)
{
clearInterval(this.timer);
this.setFocusObj(obj);
var value = parseInt(obj.value,10);
var radix = parseInt(obj.radix,10)-1;
if (obj.value>radix||obj.value<0)
{
obj.value = obj.value.substr(0,1);
}
}
Calendar.prototype.controlTime = function(cmd)
{
event.cancelBubble = true;
if (!this.fObj) return;
clearInterval(this.timer);
var cmd = event.srcElement.innerText=="5"?true:false;
var i = parseInt(this.fObj.value,10);
var radix = parseInt(this.fObj.radix,10)-1;
if (i==radix&&cmd)
{
i = 0;
}
else if (i==0&&!cmd)
{
i = radix;
}
else
{
cmd?i++:i--;
}
this.fObj.value = this.formatTime(i);
this.fObj.select();
}
Calendar.prototype.setTime = function(obj)
{
obj.value = this.formatTime(obj.value);
}
Calendar.prototype.setFocusObj = function(obj)
{
eval("c_up").disabled = eval("c_down").disabled = false;
this.fObj = obj;
}
Calendar.prototype.getTime = function()
{
var arrTime = new Array(2);
for (var i=0;i<this.getElementById("txtcalendarTime").length;i++)
{
arrTime[i] = this.getElementById("txtcalendarTime")[i].value;
}
return arrTime.join(":");
}
//SelectDate(this,'yyyy-MM-dd hh:mm:ss')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -