A very nice script calendar

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax array class document function javascript replace return

<script language= "JavaScript" >
var months = new Array ("One", "two", "three", "four", "five", "six", "seven", "eight", "Nine", "Ten", "11", "12");
var daysinmonth = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var days = new Array ("Day", "one", "two", "three", "four", "five", "six");
var classtemp;
var today=new gettoday ();
var year=today.year;
var month=today.month;
var newcal;

function getdays (month, year) {
if (1 = month) return ((0 = year% 4) && (0!= (year% 100)) | | (0 = year% 400)? 29:28;
else return daysinmonth[month];
}

function Gettoday () {
This.now = new Date ();
This.year = This.now.getFullYear ();
This.month = This.now.getMonth ();
This.day = This.now.getDate ();
}

 function Calendar () {
  newcal = new Date (year,month,1);
  today = new Gettoday ();  
  var day =-1;
  var startday = Newcal.getday ();
  var endday=getdays (Newcal.getmonth (), newcal.getfullyear ());
  var daily = 0;
  if ((Today.year = Newcal.getfullyear ()) && (Today.month = = Newcal.getmonth ())
  {
   day = Today.day;
 }
  var caltable = Document.all.caltable.tBodies.calendar;
  var intdaysinmonth =getdays (Newcal.getmonth (), newcal.getfullyear ());

  for (var intweek = 0; Intweek < caltable.rows.length;intweek++)
   for (var intday = 0;intday < caltable.rows[intweek].cells.length;intday++)
   {
    var cell = caltable.rows[ Intweek].cells[intday];
    var montemp= (Newcal.getmonth () +1) <10? ("0" + (Newcal.getmonth () +1)):(Newcal.getmonth () +1);        
     if ((Intday = = startday) && (0 = daily) {daily = 1;}
    var daytemp=daily<10? ("0" +daily):(daily);
    var d= < "+newcal.getfullyear () +"-"+montemp+"-"+daytemp+" >;
    if (day==daily) cell.classname= "Daynow";
    Else if (intday==6) cell.classname = "Daysat";
    Else if (intday==0) cell.classname = "Daysun";
    Else Cell.classname= "Day";
    if (daily > 0) && (daily <= Intdaysinmonth)
    {
     cell.innertext = daily;
     daily++
    Else
    {
     cell.classname= "CALENDARTD";
     cell.innertext = "";
   }
 }
  Document.all.year.value=year;
  document.all.month.value=month+1;
 }

function Submonth ()
{
if ((month-1) <0)
{
month=11;
Year=year-1;
Else
{
Month=month-1;
}
Calendar ();
}

function Addmonth ()
{
if ((month+1) >11)
{
month=0;
year=year+1;
Else
{
month=month+1;
}
Calendar ();
}

function setdate ()
{
if (document.all.month.value<1| | DOCUMENT.ALL.MONTH.VALUE>12)
{
Alert ("The effective range of the month is between 1-12!");
Return;
}
Year=math.ceil (Document.all.year.value);
Month=math.ceil (document.all.month.value-1);
Calendar ();
}
</Script>

<Script>
function Buttonover ()
{
var obj = window.event.srcElement;
Obj.runtimeStyle.cssText = "Background-color: #FFFFFF";
Obj.classname= "Hover";
}

function Buttonout ()
{
var obj = window.event.srcElement;
Window.settimeout (function () {obj.runtimeStyle.cssText = "";},300);
}
</Script>

<Style>
Input {font-family:verdana;font-size:9pt;text-decoration:none;background-color: #FFFFFF; height:20px;border:1px Solid #666666; color: #000000;}

. Calendar {font-family:verdana;text-decoration:none;width:170;background-color: #C0D0E8; font-size:9pt;border:0px Dotted #1C6FA5;
. CALENDARTD {font-family:verdana;font-size:7pt;color: #000000; Background-color: #f6f6f6; height:20px;width:11%; Text-align:center;

. Title {font-family:verdana;font-size:11pt;font-weight:normal;height:24px;text-align:center;color: #333333; Text-decoration:none;background-color: #A4B9D7; Border-top-width:1px;border-right-width:1px;border-bottom-width: 1px;border-left-width:1px;border-bottom-style:1px;border-top-color: #999999; Border-right-color: #999999; Border-bottom-color: #999999; Border-left-color: #999999;}

. Day {font-family:verdana;font-size:7pt;color: #243F65; Background-color: #E5E9F2; height:20px;width:11%;text-align: Center;
. Daysat {font-family:verdana;font-size:7pt;color: #FF0000; Text-decoration:none;background-color: #E5E9F2; text-align:center;height:18px;width:12%;
. Daysun {font-family:verdana;font-size:7pt;color: #FF0000; Text-decoration:none;background-color: #E5E9F2; text-align:center;height:18px;width:12%;
. Daynow {font-family:verdana;font-size:7pt;font-weight:bold;color: #000000; Background-color: #FFFFFF; height:20px; Text-align:center;

. Daytitle {font-family:verdana;font-size:9pt;color: #000000; Background-color: #C0D0E8; height:20px;width:11%; Text-align:center;
. Daysattitle {font-family:verdana;font-size:9pt;color: #FF0000; Text-decoration:none;background-color: #C0D0E8; text-align:center;height:20px;width:12%;
. Daysuntitle {font-family:verdana;font-size:9pt;color: #FF0000; Text-decoration:none;background-color: #C0D0E8; text-align:center;height:20px;width:12%;

. Daybutton {font-family:webdings;font-size:9pt;font-weight:bold;color: #243F65; Cursor:hand;text-decoration:none}

</Style>




&lt;table border= "0" cellpadding= "0" cellspacing= "1" class= "Calendar" id= "caltable" &gt;


&lt;thead&gt;


&lt;tr align= "center" valign= "Middle" &gt;


&lt;td colspan= "7" class= "Title" &gt;


&lt;a href= "Javascript:submonth ()" title= "Previous month" class= "Daybutton" &gt;3&lt;/a&gt; &lt;input name= "Year" type= "text" Size= "4" maxlength= "4" onkeydown= "if (event.keycode==13) {setdate ()}" onkeyup= "This.value=this.value.replace (/[^0-9 ]/g, "onpaste=" This.value=this.value.replace (/[^0-9]/g, ') "&gt; Year &lt;input name=" month "type=" text "size=" 1 "  Maxlength= "2" onkeydown= "if (event.keycode==13) {setdate ()}" onkeyup= "This.value=this.value.replace (/[^0-9]/g,") " Onpaste= "This.value=this.value.replace (/[^0-9]/g,") "&gt; Month &lt;a href=" Javascript:addmonth (); "Title=" Next month "Class=" Daybutton "&gt;4&lt;/a&gt;


&lt;/td&gt;


&lt;/tr&gt;


&lt;tr align= "center" valign= "Middle" &gt;


&lt;script language= "JavaScript" &gt;


document.write ("&lt;td class=daysuntitle id=diary &gt;" + days[0] + "&lt;/TD&gt;");


for (var intloop = 1; intloop &lt; days.length-1;intloop++)


document.write ("&lt;td class=daytitle id=diary&gt;" + days[intloop) + "&lt;/TD&gt;");


document.write ("&lt;td class=daysattitle id=diary&gt;" + days[intloop) + "&lt;/TD&gt;");


&lt;/Script&gt;


&lt;/TR&gt;


&lt;/thead&gt;


&lt;tbody border=1 cellspacing= "0" cellpadding= "0" id= "Calendar" Align=center onclick= "Getdiary ()" &gt;


&lt;script language= "JavaScript" &gt;


for (var intweeks = 0; intweeks &lt; 6; intweeks++)


  {


document.write ("&lt;tr style= ' Cursor:hand ' &gt;");


for (var intdays = 0; intdays &lt; days.length;intdays++) document.write ("&lt;td class=calendartd onMouseover=" Buttonover (); ' onmouseout= ' buttonout (); &gt;&lt;/TD&gt; ");


document.write ("&lt;/TR&gt;");


  }


&lt;/Script&gt;


&lt;/TBODY&gt;


&lt;/TABLE&gt;


&lt;script language= "JavaScript" &gt;


Calendar ();


&lt;/Script&gt;

Related Article

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.