?? calender.js
字號:
document.writeln("<div id='calenderdiv' style>日歷加載中...</div>");
var cal_url_redefine;
if(window.location.href.indexOf('archive')>=0) {cal_url_redefine = '../'} else { cal_url_redefine ='' };
function changecal(action,year,month)
{
var strcal;
switch(action)
{
case "nextmonth":
if(month==11)
{
month = 1;
year = year*1 + 1;
}else{
month = month*1 + 2;
}
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='下一個月' style='cursor:hand;'>> </span>";
break;
case "premonth":
if(month==0)
{
month = 12;
year = year*1 - 1;
}
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='上一個月' style='cursor:hand;'> <</span>";
break;
case "nextyear":
year = year*1 + 1;
month = month*1 + 1;
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='下一年' style='cursor:hand;'>>></span>";
break;
case "preyear":
year = year*1 - 1;
month = month*1 + 1;
strcal = "<span onmouseover=\"this.className='arrow_over'\" onmouseout=\"this.className='arrow_out'\" class='arrow_out' onclick='calender(" + year + "," + month +")' title='上一年' style='cursor:hand;'><<</span>";
break;
default:;
}
strcal = " " + strcal + " ";
return(strcal);
}
function calender(cyear,cmonth)
{
var d,d_date,d_day,d_month;
//定義星期數組
//var daylist = ["Su","Mo","Tu","We","Th","Fr","Sa"]
//定義月份數組
//var monthlist = ["January","February","March","April","May","June","July","August","September","October","November","December"]
//定義每月天數數組
var monthdates = ["31","28","31","30","31","30","31","31","30","31","30","31"]
d = new Date();
d_year = d.getYear(); //獲取年份
if (((d_year % 4 == 0) && (d_year % 100 != 0)) || (d_year % 400 == 0)) monthdates[1] = "29"; //判斷閏月,把monthdates的二月改成29
if ((cyear != "" ) || (cmonth != ""))
{
//如果用戶選擇了月份和年份,則當前的時間改為用戶設定
d.setYear(cyear);
d.setMonth(cmonth-1);
d.setDate(1);
}
d_month = d.getMonth(); //獲取當前是第幾個月
d_year = d.getYear(); //獲取年份
d_date = d.getDate(); //獲取日期
if(d_year<2000){d_year = d_year + 1900} //修正19XX年只顯示兩位的錯誤
//=========================================================輸出日歷==================================================================
var str;
str = "<table cellspacing='0' cellpadding='0' id='calender'>";
str = str + "<tr><td id='cal_title' colspan='7' >" + changecal("preyear",d_year,d_month) + changecal("premonth",d_year,d_month) + d_year + " - " + (d_month*1+1) + changecal("nextmonth",d_year,d_month) + changecal("nextyear",d_year,d_month) +"</td></tr>";
str = str + "<tr id='week'><td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td></tr>";
str = str + "<tr>";
var firstday,lastday,totalcounts,firstspace,lastspace,monthdays;
monthdays = monthdates[d.getMonth()]; //需要顯示的月份共有幾天,可以用已定義的數組來獲取
d.setDate(1); //設定日期為月份中的第一天
firstday = d.getDay(); //需要顯示的月份的第一天是星期幾
firstspace = firstday; //1號前面需要補足的的空單元格的數
d.setDate(monthdays); //設定日期為月份的最后一天
lastday = d.getDay(); //需要顯示的月份的最后一天是星期幾
lastspace = 6 - lastday; //最后一天后面需要空單元格數
totalcounts = firstspace*1 + monthdays*1 + lastspace*1; //前空單元格+總天數+后空單元格,用來控制循環
// count->大循環的變量;f_space:輸出前空單元格的循環變量;l_space:用于輸出后空單元格的循環變量
var count,flag,f_space,l_space;
flag = 0; //flag->前空單元格輸完后令flag=1不再繼續做這個小循環
for(count=1;count<=totalcounts;count++)
{
//一開始flag=0,首先輸出前空單元格,輸完以后flag=1,以后將不再執行這個循環
if(flag==0)
{
if(firstspace!=0)
{
for(f_space=1;f_space<=firstspace;f_space++)
{
str = str + "<td> </td>";
if(f_space!= firstspace) count++;
}
flag = 1;
continue;
}
}
if((count-firstspace)<=monthdays)
{
//輸出月份中的所有天數
curday = d_year+","+(d_month*1+1)+","+(count - firstspace)+"|"
linkday = d_year+","+(d_month*1+1)+","+(count - firstspace)
var today = new Date();
if( (d_year == today.getYear()) && (d_month == today.getMonth()) && ((count-firstspace) == today.getDate()) )
{
if(calstr.indexOf(curday)>=0){
str = str + "<td><span class='current havelog'><a href='"+cal_url_redefine+"logcalurl.asp?log_date="+linkday+"'>" + (count - firstspace) + "</a></span></td>"; //將本地系統中的當前天數高亮
}else{
str = str + "<td><span class='current'>" + (count - firstspace) + "</span></td>"; //將本地系統中的當前天數高亮
}
}else{
if(calstr.indexOf(curday)>=0){
str = str + "<td><span class='havelog notcurrent'><a href='"+cal_url_redefine+"logcalurl.asp?log_date="+linkday+"'>" + (count - firstspace) + "</a></span></td>"; //不用高亮的部分,有日志
}else{
str = str + "<td>" + (count - firstspace) + "</td>"; //不用高亮的部分,沒有日志
}
}
if(count%7==0)
{
if(count<totalcounts)
{
str = str + "</tr><tr>";
}else{
str = str + "</tr>";
}
}
}else{
//如果已經輸出了月份中的最后一天,就開始輸出后空單元格補足
for(l_space=1;l_space<=lastspace;l_space++)
{
str = str + "<td> </td>";
if(l_space!= lastspace) count++;
}
continue;
}
}
str = str + "</table>"
document.getElementById("calenderdiv").innerHTML = "<div id='calenderdiv'>" + str + "</div>";
}
calender("","")
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -