Calendars implemented with JavaScript

Source: Internet
Author: User
Calendar CALENDAR.CSS:


. Cal {


Background-color: #ffffff;


}





. Head {


color: #bb0000;


font-family:arial;


Font-weight:bold;


Text-align:left;


}





. Days {


color: #0000bb;


font-family:arial;


Font-weight:bold;


Text-align:right;


}





. Grey {


color: #ffffff;


font-family:arial;


Font-size:small;


Text-align:right;


}





. Links {


color: #ff0000;


font-family:arial;


Font-size:small;


Text-align:right;


}





. Today {


color: #ffffff;


Background-color: #ff0000;


font-family:arial;


Font-size:small;


Text-align:right;


}





calendar.js:


' January ', ' February ', ' March ',


' April ', ' may ', ' June ', ' July ',


' August ', ' September ', ' October ',


' November ', ' December '


);





var daysofmonth = new Array (


31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31


);





var daysofmonthly = new Array (


31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31


);





var dow = new Array (' Sun ', ' Mon ', ' Tue ', ' Wed ', ' Thu ', ' Fri ', ' Sat ',


' Sun ', ' Mon ', ' Tue ', ' Wed ', ' Thu ', ' Fri ';





var size = ' width= ' height= ' 30 ';


var border = ' border= ' 1 ';





function isleapyear (num) {


if ((num% 4 = 0) && (num% 100!= 0)) | | (num% 400 = 0))


return true;


return false;


}





function Calendarselect (month,year, offset) {


if (offset = null) offset = 0;





if (window.changemonth) {}


else {


alert (' A changemonth () function has not been defined ');


return ";


}





if (window.changeyear) {}


else {


alert (' A changeyear () function has not been defined ');


return ";


}





if (window.changeday) {}


else {


alert (' A changeday () function has not been defined ');


return ";


}





var output = ';





output = ' <form name= ' Cal ' > ';


output + + calendarhead (month,year,true);


output + + calendarmonth (month,year,offset);


Output + = ' </form> ';





return output;


}





function Calendarhead (month,year,select) {


var output = ';





output + +


' <table cellspacing= "0" class= "cal" > ' +


' <tr><td align= "left" width= "100%" class= "Head" > ' +


Moy[month-1] + ' + year +


' </td> ';





if (Select) {





output = ' <td width= ' 50% ' align= ' right ' > ' +


' <select name= ' Month "onchange=" Calmonth () ">";





for (var month=1 month<=12; month++) {


output = ' <option value= ' + month + ' "';


if (month = = month) output + = ' selected ';


output = ' > ' + moy[month-1] + ' </option> ';


}





output = ' </select> ' +


"<select name=" Year "onchange=" Calyear (); > ';





for (var year=1900 year<=2100; year++) {


output = ' <option value= ' + year + ' ";


if (year = = year) output = = ' selected ';


output = ' > ' + year + ' </option> ';


}





output = ' </select> ';


}





output = ' </td></tr></table> ';





return output;


}





function Calendarmonth (m,y,offset) {


m--;


if (offset = null) offset = 0;





firstday = new Date (y,m,1);


startday = Firstday.getday ();





if (StartDay < offset) StartDay = 7;





var days = Daysofmonth;


if (Isleapyear (Y)) days = daysofmonthly;





var output = ';





Output + +


' <table ' + border + ' cellpadding= ' 0 "class=" cal "><tr>";





for (var i=0; i<7; i++)


output = ' <td ' + size + ' class= ' days ' > ' +


Dow[i + offset] + ' </td> ';





output = ' </tr><tr> ';





var column = 0;


var lastm = M-1;


if (lastm = = 1) lastm = 11;





for (var i=0+offset; i<startday; i++, column++)


output + = ' <TD ' + size + ' class= ' grey ' > ' +


(days[lastm]-startday+i+1) + ' </td> ';





for (var i=1 i<=days[m]; i







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.