Home > Web Front-end > JS Tutorial > New algorithm for JavaScript blog-style calendar control_time and date

New algorithm for JavaScript blog-style calendar control_time and date

WBOY
Release: 2016-05-16 19:01:15
Original
1155 people have browsed it

Instructions for use:

The program is relatively simple and there are instructions in the code. Here is how to use it.
The first step is to instantiate a Calendar and set the parameters.
Parameter description:
Year: The year to be displayed
Month: The month to be displayed
SelectDay: Select the date
onSelectDay: Trigger on the selected date
onToday: Trigger on today's date
onFinish: Triggered after the calendar is drawn

Generally, SelectDay is set to the selected date, and a function is set in onSelectDay to set the style of this date.
For example, in the example, SelectDay is set to today. On the 10th of the month and set the style to onSelect on that day:

Copy the code The code is as follows:

SelectDay : new Date().setDate(10),
onSelectDay: function(o){ o.className = "onSelect"; },

and onToday is used to set the style of today’s date ,
For example, in the example, set the style of today's date to onToday:

onToday: function(o){ o.className = "onToday"; },
You can put the required settings in onFinish Calendar program.
You can get the year and month displayed by the current calendar through this.Year and this.Month.
The dates with data are also set here. For example, in the example, there is a list of dates with data in the current month, and then the corresponding dates are set according to this list:
Copy code The code is as follows:

var flag = [10,15,20];
for(var i = 0, len = flag.length; i < len; i ){
this.Days[flag[i]].innerHTML = "" flag[i] "";
}
This date list is fixed in the example. In actual applications, the corresponding date list can be obtained according to the year and month.
I personally recommend using the year and month to obtain it through ajax.

There are also two useful methods in the program: PreMonth (displays the previous month) and NextMonth (displays the next month).

Test code:
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template