<script language=JavaScript1.2>
// 一個(gè)簡(jiǎn)單的測(cè)試是否IE瀏覽器的表達(dá)式
isIE = (document.all ? true : false);
// 得到IE中各元素真正的位移量,即使這個(gè)元素在一個(gè)表格中
function getIEPosX(elt) { return getIEPos(elt,"Left"); }
function getIEPosY(elt) { return getIEPos(elt,"Top"); }
function getIEPos(elt,which) {
iPos = 0
while (elt!=null) {
iPos += elt["offset" + which]
elt = elt.offsetParent
}
return iPos
}
function getXBrowserRef(eltname) {
return (isIE ? document.all[eltname].style : document.layers[eltname]);
}
function hideElement(eltname) { getXBrowserRef(eltname).visibility = 'hidden'; }
// 按不同的瀏覽器進(jìn)行處理元件的位置
function moveBy(elt,deltaX,deltaY) {
if (isIE) {
elt.left = elt.pixelLeft + deltaX;
elt.top = elt.pixelTop + deltaY;
} else {
elt.left += deltaX;
elt.top += deltaY;
}
}
function toggleVisible(eltname) {
elt = getXBrowserRef(eltname);
if (elt.visibility == 'visible' || elt.visibility == 'show') {
elt.visibility = 'hidden';
} else {
fixPosition(eltname);
elt.visibility = 'visible';
}
}
function setPosition(elt,positionername,isPlacedUnder) {
positioner = null;
if (isIE) {
positioner = document.all[positionername];
elt.left = getIEPosX(positioner);
elt.top = getIEPosY(positioner);
} else {
positioner = document.images[positionername];
elt.left = positioner.x;
elt.top = positioner.y;
}
if (isPlacedUnder) { moveBy(elt,0,positioner.height); }
}
//——————————————————————————————————————
// 判斷瀏覽器
isIE = (document.all ? true : false);
// 初始月份及各月份天數(shù)數(shù)組
var months = new Array("一 月", "二 月", "三 月", "四 月", "五 月", "六 月", "七 月",
"八 月", "九 月", "十 月", "十一月", "十二月");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,
30, 31, 30, 31);
var displayMonth = new Date().getMonth();
var displayYear = new Date().getFullYear();
var displayDivName;
var displayElement;
function getDays(month, year) {
//測(cè)試選擇的年份是否是潤(rùn)年?
if (1 == month)
return ((0 == year % 4) && (0 != (year % 100))) ||
(0 == year % 400) ? 29 : 28;
else
return daysInMonth[month];
}
function getToday() {
// 得到今天的日期
this.now = new Date();
this.year = this.now.getFullYear();
this.month = this.now.getMonth();
this.day = this.now.getDate();
}
// 并顯示今天這個(gè)月份的日歷
today = new getToday();
function newCalendar(eltName,attachedElement) {
if (attachedElement) {
if (displayDivName && displayDivName != eltName) hideElement(displayDivName);
displayElement = attachedElement;
}
displayDivName = eltName;
today = new getToday();
var parseYear = parseInt(displayYear + '');
var newCal = new Date(parseYear,displayMonth,1);
var day = -1;
var startDayOfWeek = newCal.getDay();
if ((today.year == newCal.getFullYear()) &&
(today.month == newCal.getMonth()))
{
day = today.day;
}
var intDaysInMonth =
getDays(newCal.getMonth(), newCal.getFullYear());
var daysGrid = makeDaysGrid(startDayOfWeek,day,intDaysInMonth,newCal,eltName)
if (isIE) {
var elt = document.all[eltName];
elt.innerHTML = daysGrid;
} else {
var elt = document.layers[eltName].document;
elt.open();
elt.write(daysGrid);
elt.close();
}
}
function incMonth(delta,eltName) {
displayMonth += delta;
if (displayMonth >= 12) {
displayMonth = 0;
incYear(1,eltName);
} else if (displayMonth <= -1) {
displayMonth = 11;
incYear(-1,eltName);
} else {
newCalendar(eltName);
}
}
function incYear(delta,eltName) {
displayYear = parseInt(displayYear + '') + delta;
newCalendar(eltName);
}
function makeDaysGrid(startDay,day,intDaysInMonth,newCal,eltName) {
var daysGrid;
var month = newCal.getMonth();
var year = newCal.getFullYear();
var isThisYear = (year == new Date().getFullYear());
var isThisMonth = (day > -1)
daysGrid = '
';
daysGrid += '';
daysGrid += 'x';
daysGrid += ' ';
daysGrid += '« ';
daysGrid += '';
if (isThisMonth) { daysGrid += '' + months[month] + ''; }
else { daysGrid += months[month]; }
daysGrid += '';
daysGrid += ' »';
daysGrid += ' ';
daysGrid += '« ';
daysGrid += '';
if (isThisYear) { daysGrid += '' + year + ''; }
else { daysGrid += ''+year; }
daysGrid += '';
daysGrid += ' » ';
daysGrid += ' Su Mo Tu We Th Fr Sa ';
var dayOfMonthOfFirstSunday = (7 - startDay + 1);
for (var intWeek = 0; intWeek < 6; intWeek++) {
var dayOfMonth;
for (var intDay = 0; intDay < 7; intDay++) {
dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
if (dayOfMonth <= 0) {
daysGrid += " ";
} else if (dayOfMonth <= intDaysInMonth) {
var color = "blue";
if (day > 0 && day == dayOfMonth) color="red";
daysGrid += '';
var dayString = dayOfMonth + " ";
if (dayString.length == 6) dayString = '0' + dayString;
daysGrid += dayString;
}
}
if (dayOfMonth < intDaysInMonth) daysGrid += " ";
}
return daysGrid + " |
";
}
function setDay(day,eltName) {
displayElement.value = (displayMonth + 1) + "/" + day + "/" + displayYear;
hideElement(eltName);
}
//——————————————————————————————————————
</script>
<script language=JavaScript1.2>
function Cancel() {
hideElement("daysOfMonth");
}
</script>
<script language=JavaScript1.2>
</script>