JavaScript implementation 2016 New Year Edition calendar _javascript tips

Source: Internet
Author: User
Tags eval

First look at the effect chart, the effect is relatively simple:

Specific code:

 


JavaScript code      

Determine if the leap year function isleapyear (year) {if (year%400==0) | | (year%4==0 && year%100!=0))
  {return true;
return false;          
  }//Calendar function Createcalendar (year,month,date) {var d=new date ();  if (!year | | year<=0) {cur_year=d.getfullyear ();
  Year}else{Cur_year=year;  } if (!month | | month<=0) {cur_mon=d.getmonth ();
  Date}else{cur_mon=month-1;  } if (!date | | date<=0) {cur_date=d.getdate ();
  Date}else{cur_date=date; } month_days=new Array (31,28+isleapyear (D.getfullyear ()), 31,30,31,30,31,31,30,31,30,31);
  Days of the Month array month_firstday_date=new date (cur_year,cur_mon,1);     
  Monthdays=month_days[cur_mon]; Monthfirstday=month_firstday_date.getday ();  The first day of the month is the Week Lines=math.ceil ((monthdays+monthfirstday)/7);
  The number of rows required for the table var calendarbody= "";
    for (Var i=0;i<lines;i++) {calendarbody+= "<tr class= ' line ' >"; for (Var j=0;j<7;j++) {idx=i*7+j;//cell Natural serial number if (i==0&& idx<monthfirstday) {calendarbody+= "<td class= ' empty ' ></td>";
        }else if (idx<monthdays+monthfirstday) {var date=idx+1-monthfirstday; if (date==cur_date && cur_mon==d.getmonth () && cur_year==d.getfullyear ()) {calendarbody+= "<td
        class= ' Today ' > ' +date+ "</td>";
        }else{calendarbody+= "<td>" +date+ "</td>";
      }}else{calendarbody+= "<td class= ' empty ' ></td>";
  }} calendarbody+= "</tr>";
return calendarbody; }

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.