• 当前位置:首页>>JavaScript教程>>JavaScript基础教程>>HTML组件之:编写日历(2)
  • HTML组件之:编写日历(2)
  • ===编写日历一===

    如果指定的年数可以被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];
    }

    [1]

  • 上一篇:HTML组件之:编写日历(3)
    下一篇:HTML组件之:编写日历(1)