= = = Write Calendar one = = =
When Calendar.html calls Mycal:calendar, the calendar for the current month is displayed in the page, and the function setcal () is the main program segment, which initializes some variables and invokes the drawcal () function. We also used three other functions: Getmonthname (), GetDays (), and Leapyear (). Let's start with the last function:
The GetDays () function receives the month value and the year value, and establishes an array of 12 elements that are used to hold the number of days per month, which year is used to determine whether the leap years are in the leap, and February is 29 days, rather than a leap in 28 days. The function returns the number of days in the specified month.
The following is GetDays ():
function getDays (month, year) {//create array to hold number of days in each month var ar = new Array (n); 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]; If the specified number of years can be divisible by 4, the Leapyear () function returns "true", otherwise "false" is returned: function leapyear (year) {if (4 = = = 0)//basic rule return Tru E is leap year/* * ELSE *//else not needed if statement is "return" return false; is not a leap year} getmonthname () function returns the name of the specified 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]; The setcal () function is the main module, and we call it on the first line of the script. The function establishes a Date object for the day (now) and the first day of the month (firstdayinstance). With these objects, the setcal () function resolves all information about the first day, the day, and the last day of one months. function setcal () {//Standard Time attributes var now = new Date (), var year = Now.getfullyear (); var month = Now.getmon Th (); var monthName = getmonthname (month); var date = Now.getdate (); now = null; Create instance of first day of month, and extract the day in which it occurs var firstdayinstance = new Date (Year, Mon th, 1); var firstday = Firstdayinstance.getday (); Firstdayinstance = null; Number of days in current month var. = getDays (month, year); Call function to draw calendar drawcal (FirstDay + 1, days, date, monthName, year); }
The above is the HTML component (HTML components) of the four content, more related articles please pay attention to topic.alibabacloud.com (www.php.cn)!