HTML COMPONENTS Part 4
===Writing Calendar 1===
When calendar.html is called
MYCAL:CALENDAR, the current month's calendar will be displayed on the page. The function setCal() is the main program segment. It initializes some variables and calls the drawCal() function. We also use three other functions: getMonthName(),
getDays() and leapYear(). Let's start with the last function:
The getDays() function receives which month value and which year value, and creates an array with 12 elements to store the number of days in each month, and which year is used to determine whether it is a leap year. , February has 29 days in a leap year, instead of 28 days in a leap year. This 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(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]; } 如果指定的年数可以被4整除,那么leapYear()函数将返回“true”,否则返回”false“: function leapYear(year) { if (year % 4 == 0) // basic rule return true; // is leap year /* else */ // else not needed when statement is "return" return false; // is not leap year } getMonthName()函数返回指定月份的名字: 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]; } setCal()函数是主模块,我们在脚本的第一行调用它。该函数为当天(now)、和每月的第一天(firstDayInstance)建立一个Date对象。用这些对象,setCal()函数解析出关于一个月的第一天、当日,和最后一天的所有信息。 function setCal() { // standard time attributes var now = new Date(); var year = now.getFullYear(); 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, year); }
The above is the content of the fourth HTML component (HTML COMPONENTS). For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.
