#1 備忘錄月曆 - 蛙 (Administrator) 發表於 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> </P>
<P><FONT color=blue></FONT> </P>
<P><FONT color=blue></FONT> </P>
<P><FONT color=blue></FONT> </P>
<P><FONT color=blue><script LANGUAGE="JavaScript"><BR><!--</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> var curCookie = name + "=" + escape(value) +<BR> ((expires) ? "; expires=" + expires.toGMTString() : "" +<BR> ((path) ? "; path=" + path : "" +<BR> ((domain) ? "; domain=" + domain : "" +<BR> ((secure) ? "; secure" : ""<BR> if (!caution || (name + "=" + escape(value)).length <= 4000)<BR> document.cookie = curCookie<BR> else<BR> if (confirm("Cookie exceeds 4KB and will be cut!")<BR> 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> var prefix = name + "="<BR> var cookieStartIndex = document.cookie.indexOf(prefix)<BR> if (cookieStartIndex == -1)<BR> return null<BR> var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)<BR> if (cookieEndIndex == -1)<BR> cookieEndIndex = document.cookie.length<BR> 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> if (getCookie(name)) {<BR> document.cookie = name + "=" + <BR> ((path) ? "; path=" + path : "") +<BR> ((domain) ? "; domain=" + domain : "") +<BR> "; expires=Thu, 01-Jan-70 00:00:01 GMT"<BR> }<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> var base = new Date(0)<BR> var skew = base.getTime()<BR> if (skew > 0)<BR> date.setTime(date.getTime() - skew)<BR>}</FONT></P>
<P><FONT color=blue>function initCookie(monthName) {<BR> // initializes cookie with the following format:<BR> // ^1^^2^^3^^4^...^30^^31^</FONT></P>
<P><FONT color=blue> // initialize accumulative variable<BR> var text = ""<BR> for (var i = 1; i <= 31; ++i) {<BR> text += "^" + i + "^"<BR> }</FONT></P>
<P><FONT color=blue> var now = new Date()<BR> fixDate(now)</FONT></P>
<P><FONT color=blue> // set time to one month (31 days) in the future<BR> now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 31)</FONT></P>
<P><FONT color=blue> setCookie(monthName + "Calendar", text, now)<BR>}</FONT></P>
<P><FONT color=blue>function getSpecificReminder(num, monthName) {<BR> var prefix = "^" + num + "^"<BR> var totalCookie = getCookie(monthName + "Calendar")<BR> var startIndex = totalCookie.indexOf(prefix, 0)<BR> var startData = totalCookie.indexOf("^", startIndex + 1) + 1<BR> if (num == 31)<BR> var endData = totalCookie.length<BR> else<BR> var endData = totalCookie.indexOf("^", startData)<BR> <BR> return totalCookie.substring(startData, endData)<BR>}</FONT></P>
<P><FONT color=blue>function setSpecificReminder(num, monthName, newValue) {<BR> var prefix = "^" + num + "^"<BR> var totalCookie = getCookie(monthName + "Calendar")<BR> var startIndex = totalCookie.indexOf(prefix, 0)<BR> var startData = totalCookie.indexOf("^", startIndex + 1) + 1<BR> if (num == 31)<BR> var endData = totalCookie.length<BR> else<BR> var endData = totalCookie.indexOf("^", startData)<BR> var now = new Date()<BR> fixDate(now)</FONT></P>
<P><FONT color=blue> // set time to one month (31 days) in the future<BR> now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 31)</FONT></P>
<P><FONT color=blue> 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> if (!getCookie(monthName + "Calendar")) <BR> initCookie(monthName)<BR> var newValue = prompt("Enter reminder for current date:", getSpecificReminder(num, monthName))<BR> if (newValue) // user did not cancel<BR> setSpecificReminder(num, monthName, newValue)<BR>}</FONT></P>
<P><FONT color=blue>function getTime() {<BR> // initialize time-related variables with current time settings<BR> var now = new Date()<BR> var hour = now.getHours()<BR> var minute = now.getMinutes()<BR> now = null<BR> var ampm = "" </FONT></P>
<P><FONT color=blue> // validate hour values and set value of ampm<BR> if (hour >= 12) {<BR> hour -= 12<BR> ampm = "PM"<BR> } else<BR> ampm = "AM"<BR> hour = (hour == 0) ? 12 : hour</FONT></P>
<P><FONT color=blue> // add zero digit to a one digit minute<BR> if (minute < 10)<BR> minute = "0" + minute // do not parse this number!</FONT></P>
<P><FONT color=blue> // return time string<BR> return hour + ":" + minute + " " + ampm<BR>}</FONT></P>
<P><FONT color=blue>function leapYear(year) {<BR> if (year % 4 == 0) // basic rule<BR> return true // is leap year<BR> return false // is not leap year<BR>}</FONT></P>
<P><FONT color=blue>function getDays(month, year) {<BR> // create array to hold number of days in each month<BR> var ar = new Array(12)<BR> ar[0] = 31 // January<BR> ar[1] = (leapYear(year)) ? 29 : 28 // February<BR> ar[2] = 31 // March<BR> ar[3] = 30 // April<BR> ar[4] = 31 // May<BR> ar[5] = 30 // June<BR> ar[6] = 31 // July<BR> ar[7] = 31 // August<BR> ar[8] = 30 // September<BR> ar[9] = 31 // October<BR> ar[10] = 30 // November<BR> ar[11] = 31 // December</FONT></P>
<P><FONT color=blue> // return number of days in the specified month (parameter)<BR> return ar[month]<BR>}</FONT></P>
<P><FONT color=blue>function getMonthName(month) {<BR> // create array to hold name of each month<BR> var ar = new Array(12)<BR> ar[0] = "January"<BR> ar[1] = "February"<BR> ar[2] = "March"<BR> ar[3] = "April"<BR> ar[4] = "May"<BR> ar[5] = "June"<BR> ar[6] = "July"<BR> ar[7] = "August"<BR> ar[8] = "September"<BR> ar[9] = "October"<BR> ar[10] = "November"<BR> ar[11] = "December"</FONT></P>
<P><FONT color=blue> // return name of specified month (parameter)<BR> return ar[month]<BR>}</FONT></P>
<P><FONT color=blue>function setCal() {<BR> // standard time attributes<BR> var now = new Date()<BR> var year = now.getYear()<BR> var month = now.getMonth()<BR> var monthName = getMonthName(month)<BR> var date = now.getDate()<BR> now = null</FONT></P>
<P><FONT color=blue> // create instance of first day of month, and extract the day on which it occurs<BR> var firstDayInstance = new Date(year, month, 1)<BR> var firstDay = firstDayInstance.getDay()<BR> firstDayInstance = null</FONT></P>
<P><FONT color=blue> // number of days in current month<BR> var days = getDays(month, year)</FONT></P>
<P><FONT color=blue> // call function to draw calendar<BR> drawCal(firstDay + 1, days, date, monthName, 00 + year)<BR>}</FONT></P>
<P><FONT color=blue>function drawCal(firstDay, lastDate, date, monthName, year) {<BR> // constant table settings<BR> var headerHeight = 50 // height of the table's header cell<BR> var border = 1 // 3D height of table's border<BR> var cellspacing = 0 // width of table's border<BR> var headerColor = "midnightblue" // color of table's header<BR> var headerSize = "+3" // size of tables header font<BR> var colWidth = 60 // width of columns in table<BR> var dayCellHeight = 25 // height of cells containing days of the week<BR> var dayColor = "darkblue" // color of font representing week days<BR> var cellHeight = 40 // height of cells representing dates in the calendar<BR> var todayColor = "red" // color specifying today's date in the calendar<BR> var timeColor = "purple" // color of font representing current time</FONT></P>
<P><FONT color=blue> // create basic table structure<BR> var text = "" // initialize accumulative variable to empty string<BR> text += '<CENTER>'<BR> text += '<TABLE bordercolor=black BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings<BR> text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell<BR> text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header<BR> text += monthName + ' ' + year <BR> text += '</FONT>' // close table header's font settings<BR> text += '</TH>' // close header cell</FONT></P>
<P><FONT color=blue> // variables to hold constant settings<BR> var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'<BR> openCol += '<FONT COLOR="' + dayColor + '">'<BR> var closeCol = '</FONT></TD>'</FONT></P>
<P><FONT color=blue> // create array of abbreviated day names<BR> var weekDay = new Array(7)<BR> weekDay[0] = "Sun"<BR> weekDay[1] = "Mon"<BR> weekDay[2] = "Tues"<BR> weekDay[3] = "Wed"<BR> weekDay[4] = "Thu"<BR> weekDay[5] = "Fri"<BR> weekDay[6] = "Sat"<BR> <BR> // create first row of table to set column width and specify week day<BR> text += '<TR ALIGN="center" VALIGN="center">'<BR> for (var dayNum = 0; dayNum < 7; ++dayNum) {<BR> text += openCol + weekDay[dayNum] + closeCol <BR> }<BR> text += '</TR>'<BR> <BR> // declaration and initialization of two variables to help with tables<BR> var digit = 1<BR> var curCell = 1<BR> <BR> for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {<BR> text += '<TR ALIGN="right" VALIGN="top">'<BR> for (var col = 1; col <= 7; ++col) {<BR> if (digit > lastDate)<BR> break<BR> if (curCell < firstDay) {<BR> text += '<TD></TD>';<BR> curCell++<BR> } else {<BR> if (digit == date) { // current cell represent today's date<BR> text += '<TD HEIGHT=' + cellHeight + '>'<BR> text += '<FONT COLOR="' + todayColor + '">'<BR> 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>'<BR> text += '<BR>'<BR> text += '<FONT COLOR="' + timeColor + '" SIZE=2>'<BR> text += '<CENTER>' + getTime() + '</CENTER>'<BR> text += '</FONT>'<BR> text += '</TD>'<BR> } else<BR> 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>'<BR> digit++<BR> }<BR> }<BR> text += '</TR>'<BR> }<BR> <BR> // close all basic table tags<BR> text += '</TABLE>'<BR> text += '</CENTER>'</FONT></P>
<P><FONT color=blue> // print accumulative HTML string<BR> document.write(text) <BR>}</FONT></P>
<P><FONT color=blue>setCal()</FONT></P>
<P><FONT color=blue>// --><BR></script><BR><BR></FONT></P>