查看完整版本: 備忘錄月曆

26-5-2012 10:21

備忘錄月曆

<FONT color=blue>
<P><FONT color=#0000ff size=3>如不能顯示語法效果,可貼去本站</FONT><A href="http://www.bunbun000.com/html/index.htm" target=_blank><FONT color=red size=3>語法測試板</FONT></A><FONT color=#0000ff size=3>試看</FONT></P></FONT>
<P><FONT color=blue></FONT>&nbsp;</P>
<P><FONT color=blue></FONT>&nbsp;</P>
<P><FONT color=blue></FONT>&nbsp;</P>
<P><FONT color=blue></FONT>&nbsp;</P>
<P><FONT color=blue>&lt;script LANGUAGE="JavaScript"&gt;<BR>&lt;!--</FONT></P>
<P><FONT color=blue>// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.<BR>// Permission given to use the script provided that this notice remains as is.<BR>// Cookie functions to store and retrieve cookies<BR>//</FONT></P>
<P><FONT color=blue>// Boolean variable specified if alert should be displayed if cookie exceeds 4KB<BR>var caution = false</FONT></P>
<P><FONT color=blue>// name - name of the cookie<BR>// value - value of the cookie<BR>// [expires] - expiration date of the cookie (defaults to end of current session)<BR>// [path] - path for which the cookie is valid (defaults to path of calling document)<BR>// [domain] - domain for which the cookie is valid (defaults to domain of calling document)<BR>// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission<BR>// * an argument defaults when it is assigned null as a placeholder<BR>// * a null placeholder is not required for trailing omitted arguments<BR>function setCookie(name, value, expires, path, domain, secure) {<BR>&nbsp;var curCookie = name + "=" + escape(value) +<BR>&nbsp;&nbsp;((expires) ? "; expires=" + expires.toGMTString() : "") +<BR>&nbsp;&nbsp;((path) ? "; path=" + path : "") +<BR>&nbsp;&nbsp;((domain) ? "; domain=" + domain : "") +<BR>&nbsp;&nbsp;((secure) ? "; secure" : "")<BR>&nbsp;if (!caution || (name + "=" + escape(value)).length &lt;= 4000)<BR>&nbsp;&nbsp;document.cookie = curCookie<BR>&nbsp;else<BR>&nbsp;&nbsp;if (confirm("Cookie exceeds 4KB and will be cut!"))<BR>&nbsp;&nbsp;&nbsp;document.cookie = curCookie<BR>}</FONT></P>
<P><FONT color=blue>// name - name of the desired cookie<BR>// * return string containing value of specified cookie or null if cookie does not exist<BR>function getCookie(name) {<BR>&nbsp;var prefix = name + "="<BR>&nbsp;var cookieStartIndex = document.cookie.indexOf(prefix)<BR>&nbsp;if (cookieStartIndex == -1)<BR>&nbsp;&nbsp;return null<BR>&nbsp;var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)<BR>&nbsp;if (cookieEndIndex == -1)<BR>&nbsp;&nbsp;cookieEndIndex = document.cookie.length<BR>&nbsp;return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))<BR>}</FONT></P>
<P><FONT color=blue>// name - name of the cookie<BR>// [path] - path of the cookie (must be same as path used to create cookie)<BR>// [domain] - domain of the cookie (must be same as domain used to create cookie)<BR>// * path and domain default if assigned null or omitted if no explicit argument proceeds<BR>function deleteCookie(name, path, domain) {<BR>&nbsp;if (getCookie(name)) {<BR>&nbsp;&nbsp;document.cookie = name + "=" + <BR>&nbsp;&nbsp;((path) ? "; path=" + path : "") +<BR>&nbsp;&nbsp;((domain) ? "; domain=" + domain : "") +<BR>&nbsp;&nbsp;"; expires=Thu, 01-Jan-70 00:00:01 GMT"<BR>&nbsp;}<BR>}</FONT></P>
<P><FONT color=blue>// date - any instance of the Date object<BR>// * you should hand all instances of the Date object to this function for "repairs"<BR>// * this function is taken from Chapter 14, "Time and Date in JavaScript", in "Learn Advanced JavaScript Programming"<BR>function fixDate(date) {<BR>&nbsp;var base = new Date(0)<BR>&nbsp;var skew = base.getTime()<BR>&nbsp;if (skew &gt; 0)<BR>&nbsp;&nbsp;date.setTime(date.getTime() - skew)<BR>}</FONT></P>
<P><FONT color=blue>function initCookie(monthName) {<BR>&nbsp;// initializes cookie with the following format:<BR>&nbsp;// ^1^^2^^3^^4^...^30^^31^</FONT></P>
<P><FONT color=blue>&nbsp;// initialize accumulative variable<BR>&nbsp;var text = ""<BR>&nbsp;for (var i = 1; i &lt;= 31; ++i) {<BR>&nbsp;&nbsp;text += "^" + i + "^"<BR>&nbsp;}</FONT></P>
<P><FONT color=blue>&nbsp;var now = new Date()<BR>&nbsp;fixDate(now)</FONT></P>
<P><FONT color=blue>&nbsp;// set time to one month (31 days) in the future<BR>&nbsp;now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 31)</FONT></P>
<P><FONT color=blue>&nbsp;setCookie(monthName + "Calendar", text, now)<BR>}</FONT></P>
<P><FONT color=blue>function getSpecificReminder(num, monthName) {<BR>&nbsp;var prefix = "^" + num + "^"<BR>&nbsp;var totalCookie = getCookie(monthName + "Calendar")<BR>&nbsp;var startIndex = totalCookie.indexOf(prefix, 0)<BR>&nbsp;var startData = totalCookie.indexOf("^", startIndex + 1) + 1<BR>&nbsp;if (num == 31)<BR>&nbsp;&nbsp;var endData = totalCookie.length<BR>&nbsp;else<BR>&nbsp;&nbsp;var endData = totalCookie.indexOf("^", startData)<BR>&nbsp;<BR>&nbsp;return totalCookie.substring(startData, endData)<BR>}</FONT></P>
<P><FONT color=blue>function setSpecificReminder(num, monthName, newValue) {<BR>&nbsp;var prefix = "^" + num + "^"<BR>&nbsp;var totalCookie = getCookie(monthName + "Calendar")<BR>&nbsp;var startIndex = totalCookie.indexOf(prefix, 0)<BR>&nbsp;var startData = totalCookie.indexOf("^", startIndex + 1) + 1<BR>&nbsp;&nbsp;if (num == 31)<BR>&nbsp;&nbsp;var endData = totalCookie.length<BR>&nbsp;else<BR>&nbsp;&nbsp;var endData = totalCookie.indexOf("^", startData)<BR>&nbsp;var now = new Date()<BR>&nbsp;fixDate(now)</FONT></P>
<P><FONT color=blue>&nbsp;// set time to one month (31 days) in the future<BR>&nbsp;now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 31)</FONT></P>
<P><FONT color=blue>&nbsp;setCookie(monthName + "Calendar", totalCookie.substring(0, startData) + newValue + totalCookie.substring(endData, totalCookie.length), now)<BR>}</FONT></P>
<P><FONT color=blue>function getInput(num, monthName) {<BR>&nbsp;if (!getCookie(monthName + "Calendar")) <BR>&nbsp;&nbsp;initCookie(monthName)<BR>&nbsp;var newValue = prompt("Enter reminder for current date:", getSpecificReminder(num, monthName))<BR>&nbsp;if (newValue) // user did not cancel<BR>&nbsp;&nbsp;setSpecificReminder(num, monthName, newValue)<BR>}</FONT></P>
<P><FONT color=blue>function getTime() {<BR>&nbsp;// initialize time-related variables with current time settings<BR>&nbsp;var now = new Date()<BR>&nbsp;var hour = now.getHours()<BR>&nbsp;var minute = now.getMinutes()<BR>&nbsp;now = null<BR>&nbsp;var ampm = "" </FONT></P>
<P><FONT color=blue>&nbsp;// validate hour values&nbsp;and set value of ampm<BR>&nbsp;if (hour &gt;= 12) {<BR>&nbsp;&nbsp;hour -= 12<BR>&nbsp;&nbsp;ampm = "PM"<BR>&nbsp;} else<BR>&nbsp;&nbsp;ampm = "AM"<BR>&nbsp;hour = (hour == 0) ? 12 : hour</FONT></P>
<P><FONT color=blue>&nbsp;// add zero digit to a one digit minute<BR>&nbsp;if (minute &lt; 10)<BR>&nbsp;&nbsp;minute = "0" + minute // do not parse this number!</FONT></P>
<P><FONT color=blue>&nbsp;// return time string<BR>&nbsp;return hour + ":" + minute + " " + ampm<BR>}</FONT></P>
<P><FONT color=blue>function leapYear(year) {<BR>&nbsp;if (year % 4 == 0) // basic rule<BR>&nbsp;&nbsp;return true // is leap year<BR>&nbsp;return false // is not leap year<BR>}</FONT></P>
<P><FONT color=blue>function getDays(month, year) {<BR>&nbsp;// create array to hold number of days in each month<BR>&nbsp;var ar = new Array(12)<BR>&nbsp;ar[0] = 31 // January<BR>&nbsp;ar[1] = (leapYear(year)) ? 29 : 28 // February<BR>&nbsp;ar[2] = 31 // March<BR>&nbsp;ar[3] = 30 // April<BR>&nbsp;ar[4] = 31 // May<BR>&nbsp;ar[5] = 30 // June<BR>&nbsp;ar[6] = 31 // July<BR>&nbsp;ar[7] = 31 // August<BR>&nbsp;ar[8] = 30 // September<BR>&nbsp;ar[9] = 31 // October<BR>&nbsp;ar[10] = 30 // November<BR>&nbsp;ar[11] = 31 // December</FONT></P>
<P><FONT color=blue>&nbsp;// return number of days in the specified month (parameter)<BR>&nbsp;return ar[month]<BR>}</FONT></P>
<P><FONT color=blue>function getMonthName(month) {<BR>&nbsp;// create array to hold name of each month<BR>&nbsp;var ar = new Array(12)<BR>&nbsp;ar[0] = "January"<BR>&nbsp;ar[1] = "February"<BR>&nbsp;ar[2] = "March"<BR>&nbsp;ar[3] = "April"<BR>&nbsp;ar[4] = "May"<BR>&nbsp;ar[5] = "June"<BR>&nbsp;ar[6] = "July"<BR>&nbsp;ar[7] = "August"<BR>&nbsp;ar[8] = "September"<BR>&nbsp;ar[9] = "October"<BR>&nbsp;ar[10] = "November"<BR>&nbsp;ar[11] = "December"</FONT></P>
<P><FONT color=blue>&nbsp;// return name of specified month (parameter)<BR>&nbsp;return ar[month]<BR>}</FONT></P>
<P><FONT color=blue>function setCal() {<BR>&nbsp;// standard time attributes<BR>&nbsp;var now = new Date()<BR>&nbsp;var year = now.getYear()<BR>&nbsp;var month = now.getMonth()<BR>&nbsp;var monthName = getMonthName(month)<BR>&nbsp;var date = now.getDate()<BR>&nbsp;now = null</FONT></P>
<P><FONT color=blue>&nbsp;// create instance of first day of month, and extract the day on which it occurs<BR>&nbsp;var firstDayInstance = new Date(year, month, 1)<BR>&nbsp;var firstDay = firstDayInstance.getDay()<BR>&nbsp;firstDayInstance = null</FONT></P>
<P><FONT color=blue>&nbsp;// number of days in current month<BR>&nbsp;var days = getDays(month, year)</FONT></P>
<P><FONT color=blue>&nbsp;// call function to draw calendar<BR>&nbsp;drawCal(firstDay + 1, days, date, monthName, 00 + year)<BR>}</FONT></P>
<P><FONT color=blue>function drawCal(firstDay, lastDate, date, monthName, year) {<BR>&nbsp;// constant table settings<BR>&nbsp;var headerHeight = 50 // height of the table's header cell<BR>&nbsp;var border = 1 // 3D height of table's border<BR>&nbsp;var cellspacing = 0 // width of table's border<BR>&nbsp;var headerColor = "midnightblue" // color of table's header<BR>&nbsp;var headerSize = "+3" // size of tables header font<BR>&nbsp;var colWidth = 60 // width of columns in table<BR>&nbsp;var dayCellHeight = 25 // height of cells containing days of the week<BR>&nbsp;var dayColor = "darkblue" // color of font representing week days<BR>&nbsp;var cellHeight = 40 // height of cells representing dates in the calendar<BR>&nbsp;var todayColor = "red" // color specifying today's date in the calendar<BR>&nbsp;var timeColor = "purple" // color of font representing current time</FONT></P>
<P><FONT color=blue>&nbsp;// create basic table structure<BR>&nbsp;var text = "" // initialize accumulative variable to empty string<BR>&nbsp;text += '&lt;CENTER&gt;'<BR>&nbsp;text += '&lt;TABLE bordercolor=black BORDER=' + border + ' CELLSPACING=' + cellspacing + '&gt;' // table settings<BR>&nbsp;text += &nbsp;'&lt;TH COLSPAN=7 HEIGHT=' + headerHeight + '&gt;' // create table header cell<BR>&nbsp;text += &nbsp;&nbsp;'&lt;FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '&gt;' // set font for table header<BR>&nbsp;text += &nbsp;&nbsp;&nbsp;monthName + ' ' + year <BR>&nbsp;text += &nbsp;&nbsp;'&lt;/FONT&gt;' // close table header's font settings<BR>&nbsp;text += &nbsp;'&lt;/TH&gt;' // close header cell</FONT></P>
<P><FONT color=blue>&nbsp;// variables to hold constant settings<BR>&nbsp;var openCol = '&lt;TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '&gt;'<BR>&nbsp;openCol += '&lt;FONT COLOR="' + dayColor + '"&gt;'<BR>&nbsp;var closeCol = '&lt;/FONT&gt;&lt;/TD&gt;'</FONT></P>
<P><FONT color=blue>&nbsp;// create array of abbreviated day names<BR>&nbsp;var weekDay = new Array(7)<BR>&nbsp;weekDay[0] = "Sun"<BR>&nbsp;weekDay[1] = "Mon"<BR>&nbsp;weekDay[2] = "Tues"<BR>&nbsp;weekDay[3] = "Wed"<BR>&nbsp;weekDay[4] = "Thu"<BR>&nbsp;weekDay[5] = "Fri"<BR>&nbsp;weekDay[6] = "Sat"<BR>&nbsp;<BR>&nbsp;// create first row of table to set column width and specify week day<BR>&nbsp;text += '&lt;TR ALIGN="center" VALIGN="center"&gt;'<BR>&nbsp;for (var dayNum = 0; dayNum &lt; 7; ++dayNum) {<BR>&nbsp;&nbsp;text += openCol + weekDay[dayNum] + closeCol <BR>&nbsp;}<BR>&nbsp;text += '&lt;/TR&gt;'<BR>&nbsp;<BR>&nbsp;// declaration and initialization of two variables to help with tables<BR>&nbsp;var digit = 1<BR>&nbsp;var curCell = 1<BR>&nbsp;<BR>&nbsp;for (var row = 1; row &lt;= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {<BR>&nbsp;&nbsp;text += '&lt;TR ALIGN="right" VALIGN="top"&gt;'<BR>&nbsp;&nbsp;for (var col = 1; col &lt;= 7; ++col) {<BR>&nbsp;&nbsp;&nbsp;if (digit &gt; lastDate)<BR>&nbsp;&nbsp;&nbsp;&nbsp;break<BR>&nbsp;&nbsp;&nbsp;if (curCell &lt; firstDay) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;TD&gt;&lt;/TD&gt;';<BR>&nbsp;&nbsp;&nbsp;&nbsp;curCell++<BR>&nbsp;&nbsp;&nbsp;} else {<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (digit == date) { // current cell represent today's date<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;TD HEIGHT=' + cellHeight + '&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;FONT COLOR="' + todayColor + '"&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;A HREF="javascript:getInput(' + digit + ', \'' + monthName + '\')" onMouseOver="window.status = \'Store or retrieve data for ' + monthName + ' ' + digit + '\'; return true"&gt;&lt;FONT COLOR="' + todayColor + '"&gt;' + digit + '&lt;/FONT&gt;&lt;/A&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;BR&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;FONT COLOR="' + timeColor + '" SIZE=2&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;CENTER&gt;' + getTime() + '&lt;/CENTER&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;/FONT&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;/TD&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;} else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text += '&lt;TD HEIGHT=' + cellHeight + '&gt;&lt;A HREF="javascript:getInput(' + digit + ', \'' + monthName + '\')" onMouseOver="window.status = \'Store or retrieve data for ' + monthName + ' ' + digit + '\'; return true"&gt;' + digit + '&lt;/A&gt;&lt;/TD&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;digit++<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;text += '&lt;/TR&gt;'<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;// close all basic table tags<BR>&nbsp;text += '&lt;/TABLE&gt;'<BR>&nbsp;text += '&lt;/CENTER&gt;'</FONT></P>
<P><FONT color=blue>&nbsp;// print accumulative HTML string<BR>&nbsp;document.write(text) <BR>}</FONT></P>
<P><FONT color=blue>setCal()</FONT></P>
<P><FONT color=blue>// --&gt;<BR>&lt;/script&gt;<BR><BR></FONT></P>

25-5-2013 16:19

複製上列語法

<form name="copy">
<textarea cols="40" name="txt" rows="4" style="BACKGROUND-COLOR:#ffffff; COLOR:#000000; FONT-SIZE:9pt">
<script LANGUAGE="JavaScript">
<!--

// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Cookie functions to store and retrieve cookies
//

// Boolean variable specified if alert should be displayed if cookie exceeds 4KB
var caution = false

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000)
  document.cookie = curCookie
else
  if (confirm("Cookie exceeds 4KB and will be cut!"))
   document.cookie = curCookie
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
  return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
  cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
  document.cookie = name + "=" +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  "; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}

// date - any instance of the Date object
// * you should hand all instances of the Date object to this function for "repairs"
// * this function is taken from Chapter 14, "Time and Date in JavaScript", in "Learn Advanced JavaScript Programming"
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
  date.setTime(date.getTime() - skew)
}

function initCookie(monthName) {
// initializes cookie with the following format:
// ^1^^2^^3^^4^...^30^^31^

// initialize accumulative variable
var text = ""
for (var i = 1; i <= 31; ++i) {
  text += "^" + i + "^"
}

var now = new Date()
fixDate(now)

// set time to one month (31 days) in the future
now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 31)

setCookie(monthName + "Calendar", text, now)
}

function getSpecificReminder(num, monthName) {
var prefix = "^" + num + "^"
var totalCookie = getCookie(monthName + "Calendar")
var startIndex = totalCookie.indexOf(prefix, 0)
var startData = totalCookie.indexOf("^", startIndex + 1) + 1
if (num == 31)
  var endData = totalCookie.length
else
  var endData = totalCookie.indexOf("^", startData)

return totalCookie.substring(startData, endData)
}

function setSpecificReminder(num, monthName, newValue) {
var prefix = "^" + num + "^"
var totalCookie = getCookie(monthName + "Calendar")
var startIndex = totalCookie.indexOf(prefix, 0)
var startData = totalCookie.indexOf("^", startIndex + 1) + 1
  if (num == 31)
  var endData = totalCookie.length
else
  var endData = totalCookie.indexOf("^", startData)
var now = new Date()
fixDate(now)

// set time to one month (31 days) in the future
now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 31)

setCookie(monthName + "Calendar", totalCookie.substring(0, startData) + newValue + totalCookie.substring(endData, totalCookie.length), now)
}

function getInput(num, monthName) {
if (!getCookie(monthName + "Calendar"))
  initCookie(monthName)
var newValue = prompt("Enter reminder for current date:", getSpecificReminder(num, monthName))
if (newValue) // user did not cancel
  setSpecificReminder(num, monthName, newValue)
}

function getTime() {
// initialize time-related variables with current time settings
var now = new Date()
var hour = now.getHours()
var minute = now.getMinutes()
now = null
var ampm = ""

// validate hour values and set value of ampm
if (hour >= 12) {
  hour -= 12
  ampm = "PM"
} else
  ampm = "AM"
hour = (hour == 0) ? 12 : hour

// add zero digit to a one digit minute
if (minute < 10)
  minute = "0" + minute // do not parse this number!

// return time string
return hour + ":" + minute + " " + ampm
}

function leapYear(year) {
if (year % 4 == 0) // basic rule
  return true // is leap year
return false // is not leap year
}

function getDays(month, year) {
// create array to hold number of days in each month
var ar = new Array(12)
ar[0] = 31 // January
ar[1] = (leapYear(year)) ? 29 : 28 // February
ar[2] = 31 // March
ar[3] = 30 // April
ar[4] = 31 // May
ar[5] = 30 // June
ar[6] = 31 // July
ar[7] = 31 // August
ar[8] = 30 // September
ar[9] = 31 // October
ar[10] = 30 // November
ar[11] = 31 // December

// return number of days in the specified month (parameter)
return ar[month]
}

function getMonthName(month) {
// create array to hold name of each month
var ar = new Array(12)
ar[0] = "January"
ar[1] = "February"
ar[2] = "March"
ar[3] = "April"
ar[4] = "May"
ar[5] = "June"
ar[6] = "July"
ar[7] = "August"
ar[8] = "September"
ar[9] = "October"
ar[10] = "November"
ar[11] = "December"

// return name of specified month (parameter)
return ar[month]
}

function setCal() {
// standard time attributes
var now = new Date()
var year = now.getYear()
var month = now.getMonth()
var monthName = getMonthName(month)
var date = now.getDate()
now = null

// create instance of first day of month, and extract the day on which it occurs
var firstDayInstance = new Date(year, month, 1)
var firstDay = firstDayInstance.getDay()
firstDayInstance = null

// number of days in current month
var days = getDays(month, year)

// call function to draw calendar
drawCal(firstDay + 1, days, date, monthName, 00 + year)
}

function drawCal(firstDay, lastDate, date, monthName, year) {
// constant table settings
var headerHeight = 50 // height of the table's header cell
var border = 1 // 3D height of table's border
var cellspacing = 0 // width of table's border
var headerColor = "midnightblue" // color of table's header
var headerSize = "+3" // size of tables header font
var colWidth = 60 // width of columns in table
var dayCellHeight = 25 // height of cells containing days of the week
var dayColor = "darkblue" // color of font representing week days
var cellHeight = 40 // height of cells representing dates in the calendar
var todayColor = "red" // color specifying today's date in the calendar
var timeColor = "purple" // color of font representing current time

// create basic table structure
var text = "" // initialize accumulative variable to empty string
text += '<CENTER>'
text += '<TABLE bordercolor=black BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
text +=  '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell
text +=   '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header
text +=    monthName + ' ' + year
text +=   '</FONT>' // close table header's font settings
text +=  '</TH>' // close header cell

// variables to hold constant settings
var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
openCol += '<FONT COLOR="' + dayColor + '">'
var closeCol = '</FONT></TD>'

// create array of abbreviated day names
var weekDay = new Array(7)
weekDay[0] = "Sun"
weekDay[1] = "Mon"
weekDay[2] = "Tues"
weekDay[3] = "Wed"
weekDay[4] = "Thu"
weekDay[5] = "Fri"
weekDay[6] = "Sat"

// create first row of table to set column width and specify week day
text += '<TR ALIGN="center" VALIGN="center">'
for (var dayNum = 0; dayNum < 7; ++dayNum) {
  text += openCol + weekDay[dayNum] + closeCol
}
text += '</TR>'

// declaration and initialization of two variables to help with tables
var digit = 1
var curCell = 1

for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
  text += '<TR ALIGN="right" VALIGN="top">'
  for (var col = 1; col <= 7; ++col) {
   if (digit > lastDate)
    break
   if (curCell < firstDay) {
    text += '<TD></TD>';
    curCell++
   } else {
    if (digit == date) { // current cell represent today's date
     text += '<TD HEIGHT=' + cellHeight + '>'
     text += '<FONT COLOR="' + todayColor + '">'
     text += '<A HREF="javascript:getInput(' + digit + ', \'' + monthName + '\')" onMouseOver="window.status = \'Store or retrieve data for ' + monthName + ' ' + digit + '\'; return true"><FONT COLOR="' + todayColor + '">' + digit + '</FONT></A>'
     text += '<BR>'
     text += '<FONT COLOR="' + timeColor + '" SIZE=2>'
     text += '<CENTER>' + getTime() + '</CENTER>'
     text += '</FONT>'
     text += '</TD>'
    } else
     text += '<TD HEIGHT=' + cellHeight + '><A HREF="javascript:getInput(' + digit + ', \'' + monthName + '\')" onMouseOver="window.status = \'Store or retrieve data for ' + monthName + ' ' + digit + '\'; return true">' + digit + '</A></TD>'
    digit++
   }
  }
  text += '</TR>'
}

// close all basic table tags
text += '</TABLE>'
text += '</CENTER>'

// print accumulative HTML string
document.write(text)
}

setCal()

// -->
</script>
</textarea><br>
<input onclick="javascript:this.form.txt.focus();this.form.txt.select();" type="button" value="全選">
</form>

<br>

<script type="text/javascript"><!--
google_ad_client = "ca-pub-4078143172638881";
/* 336X280 */
google_ad_slot = "3268225205";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
頁: [1]
查看完整版本: 備忘錄月曆