作者:feiy
来源:www.ASPCool.com
热度:
2006-10-14 9:16:30
===编写日历二===
drawCal()函数做实际的画图工作,它接受以下参数:
*firstDay.当月的第一天在一星期中的第几天,该值从Date对象计数而来。例如:星期
天是一星期的第一天,星期六是第二天等等。例如:如果当月的第一天是星期四,那么
该参数是:5
*lastDate.每月的天数,在五月等于31,在六月等于30
*date.当天的日期,必须在1到lastDate之间
*monthName.当月的名字
*year.年
函数的第一部分为以后的格式控制初始化一些变量:
| 以下是引用片段: // constant table settings var border = 2; // 3D height of table's border var cellspacing = 4; // 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 += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>'; // table settings text += '<TH COLSPAN=7 HEIGHT=' + 10 + '>'; // 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 |
| 以下是引用片段: 我们保存表格单元的开始标示在openCol中,把结束标记放在closeCol中: // variables to hold constant settings var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'; openCol += '<FONT COLOR="' + dayColor + '">'; var closeCol = '</FONT><TD>'; 星期缩写存放在weekDay[] 数组中: // 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"; |
我来说两句:
推荐文章
相关文章