Do It Yourself ---- write JavaScript calendar (2)

Source: Internet
Author: User

It has been several days since the previous article.
Improved:
1. browser compatibility (IE, Firefox, Chrome)
2. Add a date Click Event
Introduce CSS (skin)
<Link rel = "stylesheet" type = "text/css" href = "calendar/skin/default/calendar.css"/>
Usage
Var calendar = new Calendar ();
Calendar. dayRenderer = todayx. calendarDayRenderer; // custom date Renderer

Calendar. addSelectedDateChangeListener (function (date, cal) {// Add the selected date Event listener
Var d = DateUtil. format (date, 'Mm-dd ');
Window. location. href = 'index. php? Date = '+ d;
}, 'A'); // This 'A'. The parameter is the id of the event processor. Optional.

Calendar. show ("calendar", 420); // It is displayed as a sub-element of the calendar container whose id is 420 in width.

Custom Renderer
Function calendarDayRenderer (week, day, div, cal, isToday) {// day =-1, indicating Space
If (day =-1 ){
Return "& nbsp ;";
} Else {
Var str = DateUtil. format (div. model. date, 'yyyy-MM-dd ');
Var ___ d = DateUtil. format (div. model. date, 'Mm-dd'); // DateUtil is a tool class in calendar. js.
Var y = div. model. date. getFullYear ();
// Str + = day <10? "0" + day: "" + day;
Var a = document. createElement ("");
A. href = "index. php? Y = "+ y +" & date = "+ ___ d;
If (isToday ){
A. title = "today" + str;
} Else {
A. title = str;
}
A. innerHTML = day;
A. style. display = "block ";
If (isToday ){
A. style. color = 'red ';
}
Return;
}
}

Author: "pcenshao"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.