移花接木:嫁接Epoch Calendar

早前,在搜集控件的时候,找到epoch calendar。那个时候登录epoch calendar的官方网站,发觉这东西竟然还是

收费的(不知道现在情况怎样)。本想收费的东西想必会有独到的地方,想不到把那份压缩过后的代码格式化后,浏

览察看代码后却还是比较失望的。代码写得不是很讨人喜欢。按我的习惯,不讨人喜欢的代码,如果api简洁强大,并

且性能好的话,我还是会考虑搜罗下来,以备后续不时之需。只不过在接着的试用中,出现的几个问题,却让我彻底

失望了。

这个控件在使用的时候,有下面几个致命的问题:

1.必须为每个需要时间控件的元素,创建一个calendar对象,calendar与元素绑定在一起。于是,在观察dom节点

的时候,会看到界面上有多少个需要calendar的元素,就会出现多少个calendar。epoch创建的calendar dom节点数量

还是比较多的,可能有几百个,消耗还是相当大的。

在当代,ajax盛行的时候,如果动态创建的需要时间控件的元素很多的话,那么这些创建的calendar节点是会一

直存在的,甚至在时间元素节点销毁掉后,calendar的节点也不会释放。就比如,我朋友的项目中,就是用大量ajax

配合innerHTML来导航界面,这些请求回来的界面,每次在innerHTML的时候都需要重新创建calendar对象与元素绑定



这点是效率问题。

2.calendar的位置显示问题。这个问题的起因也是因为每个calendar的位置一开始就与元素绑定,在创建calendar

的时候直接根据元素初始位置计算出calendar的显示位置,之后如果绑定元素的位置发生变化(比如一个隐藏的div被

show出来,把元素的位置撑到另外的一个位置),那么点击元素的时候,calendar还是现实在初始位置,这样在视觉

上,就看不出与元素的当前位置相一致了。这点是可用性问题。


基于上面的原因,我重新封装了epoch calendar,并提供更加简洁有效的api,使用方式如下所示:

 var calendar = new        GZITCalendar({calendarName:'global',lazy:true});
calendar.bind('startDate','endDate','birthDay',...);


完整的代码如下所示:



封装的代码///
function GZITCalendar(config) {
this.calendarName = config.calendarName; // mandator
this.lazy = config.lazy || false;

if (!this.lazy) {
this._createCalendar();
}

}

GZITCalendar.prototype = {

bind : function() {

var instance = this;
$A(arguments).each(function(ele) {

if (ele && $(ele) && !$(ele).binded) {

Event.observe($(ele), 'focus', instance._showCalendar
.bindAsEventListener(instance, $(ele)));

Event.observe($(ele), 'blur', instance._hideCalendar
.bind(instance));

$(ele).binded = true;// 避免重复绑定造成浪费

}

});

},

_hideCalendar : function(event, ele) {

if (!this.delegationCalendar.mousein) {
this.delegationCalendar.hide();
}

},

// 显示或者关闭calendar
_showCalendar : function(event, ele) {

if (this.lazy) {
this._createCalendar();
}
this._alignToEl(ele);

// 显示出calendar的div
this.delegationCalendar.show();

},

_createCalendar : function() {

if (!this.delegationCalendar) {
// create code...here
this.delegationCalendar = new GZEpoch(this.calendarName);
this.delegationCalendar.createCalendarEle();

}

},
_alignToEl : function(ele) {

this.delegationCalendar.initCurDay(ele);
this.delegationCalendar.attachToElement(ele);

}

}


//epoch calendar的代码,部分重构/
function GZEpoch(name, mode, multiselect) {
this.state = 0;
this.name = name;

this.mode = mode || 'popup';
this.selectMultiple = (multiselect == true);
this.curDate = new Date();
this.selectedDates = new Array();
this.calendar;
this.calHeading;
this.calCells;
this.rows;
this.cols;
this.cells = new Array();
this.monthSelect;
this.yearSelect;
this.mousein = false;
this.calConfig();
this.setDays();
this.displayYear = this.displayYearInitial;
this.displayMonth = this.displayMonthInitial;

};

// 创建出calendar节点
GZEpoch.prototype.createCalendarEle = function() {
this.createCalendar();
document.body.appendChild(this.calendar);

}

// 当前时间
GZEpoch.prototype.initCurDay = function(targetelement) {

if (targetelement.value != '') {
var dateStrs = targetelement.value.split("-");
var initDate = new Date();
initDate.setFullYear(dateStrs[0]);
initDate.setMonth(dateStrs[1] - 1);
initDate.setDate(dateStrs[2]);
this.curDate = initDate;
};

}

GZEpoch.prototype.attachToElement = function(targetelement) {

if (targetelement && targetelement.type == 'text') {
this.tgt = targetelement;
this.calendar.style.position = 'absolute';
this.topOffset = this.tgt.offsetHeight;
this.leftOffset = 0;
this.calendar.style.top = this.getTop(targetelement) + this.topOffset
+ 'px';
this.calendar.style.left = this.getLeft(targetelement)
+ this.leftOffset + 'px';

this.tgt.calendar = this;

} else {
this.container = targetelement;
this.container.appendChild(this.calendar);
};
this.state = 2;

}

GZEpoch.prototype.calConfig = function() {
this.displayYearInitial = this.curDate.getFullYear();
this.displayMonthInitial = this.curDate.getMonth();
this.rangeYearLower = 1900;
this.rangeYearUpper = 2030;
this.minDate = new Date(1900, 0, 1);
this.maxDate = new Date(2030, 0, 1);
this.startDay = 0;
this.showWeeks = true;
this.selCurMonthOnly = false;
this.clearSelectedOnChange = true;
switch (this.mode) {
case 'popup' :
this.visible = false;
break;
case 'flat' :
this.visible = true;
break;
};
this.setLang();
};
GZEpoch.prototype.setLang = function() {
this.daylist = new Array('日', '一', '二', '三', '四', '五', '六', '日', '一', '二',
'三', '四', '五', '六');
this.months_sh = new Array('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月',
'九月', '十月', '十一月', '十二月');
this.monthup_title = '下一月';
this.monthdn_title = '上一月';
this.clearbtn_caption = '取消';
this.clearbtn_title = '取消';
this.maxrange_caption = '超出最大值';
};
GZEpoch.prototype.getTop = function(element) {
var oNode = element;
var iTop = 0;
while (oNode.tagName != 'BODY') {
iTop += oNode.offsetTop;
oNode = oNode.offsetParent;
};
return iTop;
};
GZEpoch.prototype.getLeft = function(element) {
var oNode = element;
var iLeft = 0;
while (oNode.tagName != 'BODY') {
iLeft += oNode.offsetLeft;
oNode = oNode.offsetParent;
};
return iLeft;
};
GZEpoch.prototype.show = function() {
this.calendar.style.display = 'block';
this.visible = true;
};
GZEpoch.prototype.hide = function() {
this.calendar.style.display = 'none';
this.visible = false;
};
GZEpoch.prototype.toggle = function() {
if (this.visible) {
this.hide();
} else {
this.show();
}
};
GZEpoch.prototype.setDays = function() {
this.daynames = new Array();
var j = 0;
for (var i = this.startDay; i < this.startDay + 7; i++) {
this.daynames[j++] = this.daylist[i];
};
this.monthDayCount = new Array(31, ((this.curDate.getFullYear() - 2000) % 4
? 28
: 29), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
};
GZEpoch.prototype.setClass = function(element, className) {
element.setAttribute('class', className);
element.setAttribute('className', className);
};
GZEpoch.prototype.createCalendar = function() {
var tbody, tr, td;
this.calendar = document.createElement('table');
this.calendar.setAttribute('id', this.name + '_calendar');
this.setClass(this.calendar, 'calendar');
this.calendar.onselectstart = function() {
return false;
};
this.calendar.ondrag = function() {
return false;
};
tbody = document.createElement('tbody');
tr = document.createElement('tr');
td = document.createElement('td');
td.appendChild(this.createMainHeading());
tr.appendChild(td);
tbody.appendChild(tr);
tr = document.createElement('tr');
td = document.createElement('td');
td.appendChild(this.createDayHeading());
tr.appendChild(td);
tbody.appendChild(tr);
tr = document.createElement('tr');
td = document.createElement('td');
td.setAttribute('id', this.name + '_cell_td');
this.calCellContainer = td;
td.appendChild(this.createCalCells());
tr.appendChild(td);
tbody.appendChild(tr);
tr = document.createElement('tr');
td = document.createElement('td');
td.appendChild(this.createFooter());
tr.appendChild(td);
tbody.appendChild(tr);
this.calendar.appendChild(tbody);
this.calendar.owner = this;
this.calendar.onmouseover = function() {
this.owner.mousein = true;
};
this.calendar.onmouseout = function() {
this.owner.mousein = false;
};
};
GZEpoch.prototype.createMainHeading = function() {
var container = document.createElement('div');
container.setAttribute('id', this.name + '_mainheading');
var bg_iframe = document.createElement('iframe');
container.appendChild(bg_iframe);
bg_iframe.setAttribute('id', 'bg');
bg_iframe.setAttribute('frameBorder', '0px');
this.setClass(container, 'mainheading');
this.monthSelect = document.createElement('select');
this.yearSelect = document.createElement('select');
var monthDn = document.createElement('input'), monthUp = document
.createElement('input');
var opt, i;
for (i = 0; i < 12; i++) {
opt = document.createElement('option');
opt.setAttribute('value', i);
if (this.state == 0 && this.displayMonth == i) {
opt.setAttribute('selected', 'selected');
};
opt.appendChild(document.createTextNode(this.months_sh[i]));
this.monthSelect.appendChild(opt);
};
for (i = this.rangeYearLower; i <= this.rangeYearUpper; i++) {
opt = document.createElement('option');
opt.setAttribute('value', i);
if (this.state == 0 && this.displayYear == i) {
opt.setAttribute('selected', 'selected');
};
opt.appendChild(document.createTextNode(i));
this.yearSelect.appendChild(opt);
};
monthUp.setAttribute('type', 'button');
monthUp.setAttribute('value', '>');
monthUp.setAttribute('title', this.monthup_title);
monthDn.setAttribute('type', 'button');
monthDn.setAttribute('value', '<');
monthDn.setAttribute('title', this.monthdn_title);
Element.addClassName(monthDn, "userbutton");
Element.addClassName(monthUp, "userbutton");
this.monthSelect.owner = this.yearSelect.owner = monthUp.owner = monthDn.owner = this;
monthUp.onmouseup = function() {
this.owner.nextMonth();
};
monthDn.onmouseup = function() {
this.owner.prevMonth();
};
this.monthSelect.onchange = function() {
this.owner.displayMonth = this.value;
this.owner.displayYear = this.owner.yearSelect.value;
this.owner.goToMonth(this.owner.displayYear, this.owner.displayMonth);
};
this.yearSelect.onchange = function() {
this.owner.displayMonth = this.owner.monthSelect.value;
this.owner.displayYear = this.value;
this.owner.goToMonth(this.owner.displayYear, this.owner.displayMonth);
};
container.appendChild(monthDn);
container.appendChild(this.monthSelect);
container.appendChild(this.yearSelect);
container.appendChild(monthUp);
return container;
};
GZEpoch.prototype.createFooter = function() {
var container = document.createElement('div');
var clearSelected = document.createElement('input');
clearSelected.setAttribute('type', 'button');
clearSelected.setAttribute('value', this.clearbtn_caption);
clearSelected.setAttribute('title', this.clearbtn_title);
clearSelected.owner = this;
clearSelected.onclick = function() {
this.owner.resetSelections(false);
};
Element.addClassName(clearSelected, "userbutton");
container.appendChild(clearSelected);
return container;
};
GZEpoch.prototype.resetSelections = function(returnToDefaultMonth) {
this.selectedDates = new Array();
this.rows = new Array(false, false, false, false, false, false, false);
this.cols = new Array(false, false, false, false, false, false, false);
if (this.tgt) {
if (this.mode == 'popup') {
this.hide();
}
};
if (returnToDefaultMonth == true) {
this.goToMonth(this.displayYearInitial, this.displayMonthInitial);
} else {
this.reDraw();
}
};
GZEpoch.prototype.createDayHeading = function() {
this.calHeading = document.createElement('table');
this.calHeading.setAttribute('id', this.name + '_caldayheading');
this.setClass(this.calHeading, 'caldayheading');
var tbody, tr, td;
tbody = document.createElement('tbody');
tr = document.createElement('tr');
this.cols = new Array(false, false, false, false, false, false, false);
if (this.showWeeks) {
td = document.createElement('td');
td.setAttribute('class', 'wkhead');
td.setAttribute('className', 'wkhead');
tr.appendChild(td);
};
for (var dow = 0; dow < 7; dow++) {
td = document.createElement('td');
td.appendChild(document.createTextNode(this.daynames[dow]));
if (this.selectMultiple) {
td.headObj = new CalHeading(this, td, (dow + this.startDay < 7
? dow + this.startDay
: dow + this.startDay - 7));
};
tr.appendChild(td);
};
tbody.appendChild(tr);
this.calHeading.appendChild(tbody);
return this.calHeading;
};
GZEpoch.prototype.createCalCells = function() {
this.rows = new Array(false, false, false, false, false, false);
this.cells = new Array();
var row = -1, totalCells = (this.showWeeks ? 48 : 42);
var beginDate = new Date(this.displayYear, this.displayMonth, 1);
var endDate = new Date(this.displayYear, this.displayMonth,
this.monthDayCount[this.displayMonth]);
var sdt = new Date(beginDate);
sdt.setDate(sdt.getDate() + (this.startDay - beginDate.getDay())
- (this.startDay - beginDate.getDay() > 0 ? 7 : 0));
this.calCells = document.createElement('table');
this.calCells.setAttribute('id', this.name + '_calcells');
this.setClass(this.calCells, 'calcells');
var tbody, tr, td;
tbody = document.createElement('tbody');
for (var i = 0; i < totalCells; i++) {
if (this.showWeeks) {
if (i % 8 == 0) {
row++;
tr = document.createElement('tr');
td = document.createElement('td');
if (this.selectMultiple) {
td.weekObj = new WeekHeading(this, td, sdt.getWeek(), row)
} else {
td.setAttribute('class', 'wkhead');
td.setAttribute('className', 'wkhead');
};
td.appendChild(document.createTextNode(sdt.getWeek()));
tr.appendChild(td);
i++;
}
} else if (i % 7 == 0) {
row++;
tr = document.createElement('tr');
};
td = document.createElement('td');
td.appendChild(document.createTextNode(sdt.getDate()));
var cell = new CalCell(this, td, sdt, row);
this.cells.push(cell);
td.cellObj = cell;
sdt.setDate(sdt.getDate() + 1);
tr.appendChild(td);
tbody.appendChild(tr);
};
this.calCells.appendChild(tbody);
this.reDraw();
return this.calCells;
};
GZEpoch.prototype.reDraw = function() {
this.state = 1;
var i, j;
for (i = 0; i < this.cells.length; i++) {
this.cells[i].selected = false;
};
for (i = 0; i < this.cells.length; i++) {
for (j = 0; j < this.selectedDates.length; j++) {
if (this.cells[i].date.getUeDay() == this.selectedDates[j]
.getUeDay()) {
this.cells[i].selected = true;
}
};
this.cells[i].setClass();
};
this.state = 2;
};
GZEpoch.prototype.deleteCells = function() {
this.calCellContainer.removeChild(this.calCellContainer.firstChild);
this.cells = new Array();
};
GZEpoch.prototype.goToMonth = function(year, month) {
this.monthSelect.value = this.displayMonth = month;
this.yearSelect.value = this.displayYear = year;
this.deleteCells();
this.calCellContainer.appendChild(this.createCalCells());
};
GZEpoch.prototype.nextMonth = function() {
if (this.monthSelect.value < 11) {
this.monthSelect.value++;
} else {
if (this.yearSelect.value < this.rangeYearUpper) {
this.monthSelect.value = 0;
this.yearSelect.value++;
} else {
alert(this.maxrange_caption);
}
};
this.displayMonth = this.monthSelect.value;
this.displayYear = this.yearSelect.value;
this.deleteCells();
this.calCellContainer.appendChild(this.createCalCells());
};
GZEpoch.prototype.prevMonth = function() {
if (this.monthSelect.value > 0)
this.monthSelect.value--;
else {
if (this.yearSelect.value > this.rangeYearLower) {
this.monthSelect.value = 11;
this.yearSelect.value--;
} else {
alert(this.maxrange_caption);
}
};
this.displayMonth = this.monthSelect.value;
this.displayYear = this.yearSelect.value;
this.deleteCells();
this.calCellContainer.appendChild(this.createCalCells());
};
GZEpoch.prototype.addZero = function(vNumber) {
return ((vNumber < 10) ? '0' : '') + vNumber;
};
GZEpoch.prototype.addDates = function(dates, redraw) {
var j, in_sd;
for (var i = 0; i < dates.length; i++) {
in_sd = false;
for (j = 0; j < this.selectedDates.length; j++) {
if (dates[i].getUeDay() == this.selectedDates[j].getUeDay()) {
in_sd = true;
break;
}
};
if (!in_sd) {
this.selectedDates.push(dates[i]);
}
};
if (redraw != false) {
this.reDraw();
}
};
GZEpoch.prototype.removeDates = function(dates, redraw) {
var j;
for (var i = 0; i < dates.length; i++) {
for (j = 0; j < this.selectedDates.length; j++) {
if (dates[i].getUeDay() == this.selectedDates[j].getUeDay()) {
this.selectedDates.splice(j, 1);
}
}
};
if (redraw != false) {
this.reDraw();
}
};
GZEpoch.prototype.outputDate = function(vDate, vFormat) {
var vDay = this.addZero(vDate.getDate());
var vMonth = this.addZero(vDate.getMonth() + 1);
var vYearLong = this.addZero(vDate.getFullYear());
var vYearShort = this.addZero(vDate.getFullYear().toString()
.substring(3, 4));
var vYear = (vFormat.indexOf('yyyy') > -1 ? vYearLong : vYearShort);
var vHour = this.addZero(vDate.getHours());
var vMinute = this.addZero(vDate.getMinutes());
var vSecond = this.addZero(vDate.getSeconds());
return vFormat.replace(/dd/g, vDay).replace(/mm/g, vMonth).replace(
/y{1,4};/g, vYear).replace(/hh/g, vHour).replace(/nn/g, vMinute)
.replace(/ss/g, vSecond);
};
GZEpoch.prototype.updatePos = function(target) {
this.calendar.style.top = this.getTop(target) + this.topOffset + 'px'
this.calendar.style.left = this.getLeft(target) + this.leftOffset + 'px'
};
function CalHeading(owner, tableCell, dow) {
this.owner = owner;
this.tableCell = tableCell;
this.dayOfWeek = dow;
this.tableCell.onclick = this.onclick;
};
CalHeading.prototype.onclick = function() {
var owner = this.headObj.owner;
var sdates = owner.selectedDates;
var cells = owner.cells;
owner.cols[this.headObj.dayOfWeek] = !owner.cols[this.headObj.dayOfWeek];
for (var i = 0; i < cells.length; i++) {
if (cells[i].dayOfWeek == this.headObj.dayOfWeek
&& (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth
&& cells[i].date.getFullYear() == owner.displayYear)) {
if (owner.cols[this.headObj.dayOfWeek]) {
if (owner.selectedDates.arrayIndex(cells[i].date) == -1) {
sdates.push(cells[i].date);
}
} else {
for (var j = 0; j < sdates.length; j++) {
if (cells[i].dayOfWeek == sdates[j].getDay()) {
sdates.splice(j, 1);
break;
}
}
};
cells[i].selected = owner.cols[this.headObj.dayOfWeek];
}
};
owner.reDraw();
};
function WeekHeading(owner, tableCell, week, row) {
this.owner = owner;
this.tableCell = tableCell;
this.week = week;
this.tableRow = row;
this.tableCell.setAttribute('class', 'wkhead');
this.tableCell.setAttribute('className', 'wkhead');
this.tableCell.onclick = this.onclick;
};
WeekHeading.prototype.onclick = function() {
var owner = this.weekObj.owner;
var cells = owner.cells;
var sdates = owner.selectedDates;
var i, j;
owner.rows[this.weekObj.tableRow] = !owner.rows[this.weekObj.tableRow];
for (i = 0; i < cells.length; i++) {
if (cells[i].tableRow == this.weekObj.tableRow) {
if (owner.rows[this.weekObj.tableRow]
&& (!owner.selCurMonthOnly || cells[i].date.getMonth() == owner.displayMonth
&& cells[i].date.getFullYear() == owner.displayYear)) {
if (owner.selectedDates.arrayIndex(cells[i].date) == -1) {
sdates.push(cells[i].date);
}
} else {
for (j = 0; j < sdates.length; j++) {
if (sdates[j].getTime() == cells[i].date.getTime()) {
sdates.splice(j, 1);
break;
}
}
}
}
};
owner.reDraw();
};
function CalCell(owner, tableCell, dateObj, row) {
this.owner = owner;
this.tableCell = tableCell;
this.cellClass;
this.selected = false;
this.date = new Date(dateObj);
this.dayOfWeek = this.date.getDay();
this.week = this.date.getWeek();
this.tableRow = row;
this.tableCell.onclick = this.onclick;
this.tableCell.onmouseover = this.onmouseover;
this.tableCell.onmouseout = this.onmouseout;
this.setClass();
};
CalCell.prototype.onmouseover = function() {
this.setAttribute('class', this.cellClass + ' hover');
this.setAttribute('className', this.cellClass + ' hover');
};
CalCell.prototype.onmouseout = function() {
this.cellObj.setClass();
};
CalCell.prototype.onclick = function() {
var cell = this.cellObj;
var owner = cell.owner;
if (!owner.selCurMonthOnly || cell.date.getMonth() == owner.displayMonth
&& cell.date.getFullYear() == owner.displayYear) {
if (owner.selectMultiple == true) {
if (!cell.selected) {
if (owner.selectedDates.arrayIndex(cell.date) == -1) {
owner.selectedDates.push(cell.date);
}
} else {
var tmp = owner.selectedDates;
for (var i = 0; i < tmp.length; i++) {
if (tmp[i].getUeDay() == cell.date.getUeDay()) {
tmp.splice(i, 1);
}
}
}
} else {
owner.selectedDates = new Array(cell.date);
if (owner.tgt) {
owner.tgt.value = owner.selectedDates[0].dateFormat();
if (owner.mode == 'popup') {
owner.hide();
}
}
};
owner.reDraw();
}
};
CalCell.prototype.setClass = function() {
if (this.selected) {
this.cellClass = 'cell_selected';
} else if (this.owner.displayMonth != this.date.getMonth()) {
this.cellClass = 'notmnth';
} else if (this.date.getDay() > 0 && this.date.getDay() < 6) {
this.cellClass = 'wkday';
} else {
this.cellClass = 'wkend';
};
if (this.date.getFullYear() == this.owner.curDate.getFullYear()
&& this.date.getMonth() == this.owner.curDate.getMonth()
&& this.date.getDate() == this.owner.curDate.getDate()) {
this.cellClass = this.cellClass + ' curdate';
};
this.tableCell.setAttribute('class', this.cellClass);
this.tableCell.setAttribute('className', this.cellClass);
};
Date.prototype.getDayOfYear = function() {
return parseInt((this.getTime() - new Date(this.getFullYear(), 0, 1)
.getTime())
/ 86400000 + 1);
};
Date.prototype.getWeek = function() {
return parseInt((this.getTime() - new Date(this.getFullYear(), 0, 1)
.getTime())
/ 604800000 + 1);
};
Date.prototype.getUeDay = function() {
return parseInt(Math.floor((this.getTime() - this.getTimezoneOffset()
* 60000)
/ 86400000));
};
Date.prototype.dateFormat = function(format) {
if (!format) {
format = 'Y-m-d';
};
LZ = function(x) {
return (x < 0 || x > 9 ? '' : '0') + x
};
var MONTH_NAMES = new Array('一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月',
'九月', '十月', '十一月', '十二月', '一月', '二月', '三月', '四月', '五月', '六月', '七月',
'八月', '九月', '十月', '十一月', '十二月');
var DAY_NAMES = new Array('日', '一', '二', '三', '四', '五', '六', '日', '一', '二',
'三', '四', '五', '六');
format = format + "";
var result = "";
var i_format = 0;
var c = "";
var token = "";
var y = this.getFullYear().toString();
var M = this.getMonth() + 1;
var d = this.getDate();
var E = this.getDay();
var H = this.getHours();
var m = this.getMinutes();
var s = this.getSeconds();
var yyyy, yy, MMM, MM, dd, hh, h, mm, ss, ampm, HH, H, KK, K, kk, k;
var value = new Object();
value['Y'] = y.toString();
value['y'] = y.substring(2);
value['n'] = M;
value['m'] = LZ(M);
value['F'] = MONTH_NAMES[M - 1];
value['M'] = MONTH_NAMES[M + 11];
value['j'] = d;
value['d'] = LZ(d);
value['D'] = DAY_NAMES[E + 7];
value['l'] = DAY_NAMES[E];
value['G'] = H;
value['H'] = LZ(H);
if (H == 0) {
value['g'] = 12;
} else if (H > 12) {
value['g'] = H - 12;
} else {
value['g'] = H;
};
value['h'] = LZ(value['g']);
if (H > 11) {
value['a'] = 'pm';
value['A'] = 'PM';
} else {
value['a'] = 'am';
value['A'] = 'AM';
};
value['i'] = LZ(m);
value['s'] = LZ(s);
while (i_format < format.length) {
c = format.charAt(i_format);
token = "";
while ((format.charAt(i_format) == c) && (i_format < format.length)) {
token += format.charAt(i_format++);
};
if (value[token] != null) {
result = result + value[token];
} else {
result = result + token;
}
};
return result;
};
Array.prototype.arrayIndex = function(searchVal, startIndex) {
startIndex = (startIndex != null ? startIndex : 0);
for (var i = startIndex; i < this.length; i++) {
if (searchVal == this[i]) {
return i;
}
};
return -1;
};


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值