国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

HTML組件(HTML COMPONENTS)之四

2024-04-27 13:54:12
字體:
供稿:網(wǎng)友

 ===編寫日歷一===

  當calendar.html調(diào)用 MYCAL:CALENDAR,當月的日歷將會顯示在頁面中,函數(shù)setCal()是主要程序段,它初始化一些變量并調(diào)用drawCal()函數(shù)。我們也使用了三個別的函數(shù):getMonthName()、 getDays() 和 leapYear()。讓我們從最后一個函數(shù)開始:

  getDays()函數(shù)接收哪月值和哪年值,并且建立一個有12個元素的數(shù)組,用來存放每月的天數(shù),哪一年用來決定是不是閏年,在閏年中二月是29天,而不是閏年是28天。該函數(shù)返回指定月份的天數(shù)。

以下是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];
}

如果指定的年數(shù)可以被4整除,那么leapYear()函數(shù)將返回“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()函數(shù)返回指定月份的名字:
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()函數(shù)是主模塊,我們在腳本的第一行調(diào)用它。該函數(shù)為當天(now)、和每月的第一天(firstDayInstance)建立一個Date對象。用這些對象,setCal()函數(shù)解析出關(guān)于一個月的第一天、當日,和最后一天的所有信息。

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);
}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 噶尔县| 聂荣县| 台前县| 滨州市| 宁陕县| 离岛区| 策勒县| 永仁县| 腾冲县| 江源县| 鄂州市| 鄂托克旗| 滦平县| 安丘市| 乐安县| 会理县| 涪陵区| 九寨沟县| 玉环县| 通州市| 静安区| 普宁市| 汪清县| 宜兰县| 鞍山市| 酉阳| 金寨县| 利川市| 板桥市| 城步| 临猗县| 渝中区| 磴口县| 桦川县| 都兰县| 湛江市| 固原市| 壶关县| 常山县| 金坛市| 奉新县|