Learn to write JS Calender Calendar control _javascript Skills

Source: Internet
Author: User
Tags getdate

Recently looked at the JS date of some functions, suddenly thought of the calendar control, so try to write a, as a background programmer I have a limited level, we hold the attitude of learning to see me write this example bar, learning progress together!

First, a commonly used date function:

Date (Year,month,day)

var date=new date ();

Get year

var year=this.date.getfullyear ();

Get the month, this is the monthly index so it takes +1

var month=this.date.getmonth () +1;

Get the date of the day

var day=this.date.getdate ();

Gets the day of the week and returns 0. Sunday 1 weeks 12 weeks 23 weeks 34 weeks 45 weeks 56. Saturday

var week=this.date.getday ();

get the month number one is the week

 var   getweekday=function (year,month,day) {
      var date=new date (year,month,day);
      return Date.getday ();
      }

var  weekstart= Getweekday (This.year, this.month-1, 1)

Get the number of days of the month

var getmonthdays=function (year,month) {
      var date=new date (year,month,0);
      return Date.getdate ();
    }
var  monthdays= this.getmonthdays (this.year,this.month);

Well, we use the parameters on so much, the back is actually about the date of the week some of the operation and judgment, dynamic splicing label, the following directly to my example sent out:

Effect Chart:

 

The

Code has been changed again to change the view table to Div, which is to solve the tableinnerhtml of IE's read-only problem. Additional options are added for the purpose of being configurable.
The above code has a simple description, function is the most basic, if more in-depth do can be extended, I hope this article can give you some inspiration.

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.