SoFunction
Updated on 2025-03-10

Another calendar input effect does not consider compatibility, IE pass


[Ctrl+A Select all Note:Introducing external Js requires refreshing the page before execution]

It was urgent, so compatibility was not considered.
Implemented through two classes, one is the panel class and the other is the calendar class.
Since all public js are loaded at one time in the top-level window when I was developing, the current window object needs to be passed in when creating an object in the child window, for example: var panel = new (self); If the self parameter is not passed, the default is the window that loads js.

The Gregorian algorithm that marcian looked for online is a bit complicated, haha. I get the maximum number of days in the current month, and the day of the week in the first day of the current month, which is directly implemented through the Date function that comes with JS.
Copy the codeThe code is as follows:

// Get the maximum number of days in the month
//asfman provides an easier way: return (new Date(y, m+1, 0)).getDate()
function GetDates(year, month)
{
    var date = new Date(year, month, 31);
    return 31 - () || 31;
}
// Get the first day of the week is the first day of the month
function GetFirstDay(year, month)
{
    return (new Date(year, month, 1)).getDay();


/* The following part is not allowed, because even if new Date(2007, -1, 31) occurs, Date will automatically convert this phenomenon to Date(2006, 12, 31)
    if(month < 0)
    {
        month = 11;
        year--;
    }
    if(month == 12)
    {
        month = 0;
        year++;
    }*/