New JavaScript blog-style calendar Control Algorithm

Source: Internet
Author: User

Instructions for use:

ProgramRelatively simple,CodeThere are instructions in this section. Here we will talk about how to use it.
First, instantiate a calendar and set parameters.
Parameter description:
Year: Year to be displayed
Month: The month to be displayed.
Selectday: select a date
Onselectday: triggered on the selected date
Ontoday: triggered on the current day
Onfinish: triggered after the calendar is painted

Generally, selectday is set to the selected date, and a function is set in onselectday to set the style of the date,
For example, set selectday In the instance to "10" of this month and "onselect" in the style of that day:Copy codeThe Code is as follows: selectday: new date (). setdate (10 ),
Onselectday: function (o) {o. classname = "onselect ";},

Ontoday is used to set the style of today's date,
For example, in the instance, set the date style to ontoday:

Ontoday: function (o) {o. classname = "ontoday ";},
In onfinish, you can set the calendar program.
You can use this. year and this. Month to obtain the year and month displayed in the current calendar.
The date with data is also set here. For example, the instance contains a list of date with data for the current month, and then the corresponding date is set according to the list:Copy codeThe Code is as follows: var flag = [10, 15, 20];
For (VAR I = 0, Len = flag. length; I <Len; I ++ ){
This. days [flag [I]. innerhtml = "<a href = 'javascript: void (0); 'onclick = \" alert ('date is: "+ this. year + "/" + this. month + "/" + flag [I] + "'); Return false; \"> "+ flag [I] +" </a> ";
}

The date list is fixed in the instance. In actual application, you can obtain the corresponding date list based on the year month,
We recommend that you use ajax to obtain the year and month.

There are two useful methods in the program: premonth (show the previous month) and nextmonth (show the next month ).

Test code:Xmlns = "http://www.w3.org/1999/xhtml">


<>

2008Year8Month

Day I II 3. Thu V. Sat.

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.