JavaScript Write Calendar Code

Source: Internet
Author: User


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link rel=stylesheet href= ". /.. /images/ntstyles.css "type=" Text/css ">
<title>Canlender--JavaScript</title>
<style>
TD {
Font-family:arial, Helvetica, Sans-serif;
font-size:30px;
}

</style>

<script language= "JavaScript" >
function Loadend ()
{
Parent.funpool.showPage ();
}

function Out_branch (ButtonID)
{
if (buttonid==0)
{
if (parent.varpool.RegDate = = "")
return 0;
}

Parent.funpool.button_Branch (ButtonID);
}

function Scrkey ()
{
if (Window.event.keyCode = = 8 | | window.event.keyCode = = 9)
{
Window.event.keyCode = 16;
}
}
</script>

<body background= ". /.. /images/background/showtxt.jpg "onload=" Loadend () "onkeydown=" Scrkey () ">
<div style= ' Position:absolute; width:790; height:50; Z-index:1; left:0px; Top:107px ' align= "center" >
<p class= ' title1 ' > Please select appointment time </p>
</div>

<div style= ' Position:absolute; width:435px; height:38px; Z-index:1; left:45px; top:520px ' align= "left" >
<p class= ' title1 ' style= "font-size:20px; color:fc0000 "> Warm reminder: Appointment date must be greater than current date </p>
</div>

<div id= ' layer ' style= ' visibility:;p osition:absolute; width:135; height:61px; Z-index:1; left:481px; top:515px ' >
<a onmousedown= "Out_branch (2)" class= "BT" >
</a></div>

<div id= ' layer ' style= ' visibility:;p osition:absolute; width:135; height:60; Z-index:1; left:651px; top:515px ' >
<a onmousedown= "Out_branch (1)" class= "BT" >
</a></div>

<table border= "0" cellpadding= "0" cellspacing= "0" width= "" "hight=" "style=" position:absolute;top:150 " left:25; " >
&LT;TR&GT;&LT;TD id=cc>
</td></tr></table>
</body>
<script language= "JavaScript" >

function Runnian (the_year)
{
if (the_year%100==0)
{
if (the_year%400==0)
return true;
Else
return false;
}
Else
{
if (the_year%4==0)
return true;
Else
return false;
}
}


function Getweekday (the_year,the_month)
{
var Allday = 0;
Alert ("the_year=" +the_year);
if (the_year>2000)
{
For (i=2000;i<the_year; i++)
if (Runnian (i))
Allday + = 366;
Else
Allday + = 365;

for (I=1; i<the_month; i++)
{
Switch (i)
{
Case 1:allday + = 31; Break
Case 2:
if (Runnian (the_year))
Allday + = 29;
Else
Allday + = 28;
Break
Case 3:allday + = 31; Break
Case 4:allday + = 30; Break
Case 5:allday + = 31; Break
Case 6:allday + = 30; Break
Case 7:allday + = 31; Break
Case 8:allday + = 31; Break
Case 9:allday + = 30; Break
Case 10:allday + = 31; Break
Case 11:allday + = 30; Break
Case 12:allday + = 31; Break
}
}
}
Alert ("allday=" +allday);
Return (allday+6)%7;
}

function Chooseday (the_year,the_month,the_day)
{
var FirstDay;
var completely_date;
var The_monthr,the_dayr;
Completely_date = The_year + "-" + The_month + "-" + the_day;
Else
Completely_date = "No Choose";
Showdate is just a thing to show and use,
If the outside wants to reference the time here, you can refer to the full date by using Completely_date
can also be cited by The_year,the_month,the_day, respectively, the year, month, day
When you select a month and year, the full date is considered not selected
FirstDay = Getweekday (the_year,the_month);
Alert ("firstday=" +firstday);
Showcalender (The_year,the_month,the_day,firstday);
}

function Getthisdate (the_year,the_month,the_day)
{

var The_monthr,the_dayr;

if (number (the_month) <10)
The_monthr = "0" + the_month;
Else
The_monthr = The_month;

if (number (The_day) < 10)
The_dayr = "0" + the_day;
Else
The_dayr = The_day;

Parent.varpool.RegDate = the_year+ "" +the_monthr+the_dayr;
Out_branch (0);
Parent.funpool.button_Branch (0);
Alert (the_year+ "" +the_monthr+the_dayr);
}

function Nextmonth (the_year,the_month)
{
if (the_month==12)
Chooseday (the_year+1,1,1);
Else
Chooseday (the_year,the_month+1,1);
}

function Prevmonth (the_year,the_month)
{
if (the_month==1)
Chooseday (the_year-1,12,1);
Else
Chooseday (the_year,the_month-1,1);
}

function Prevyear (the_year,the_month)
{
Chooseday (the_year-1,the_month,1);
}

function Nextyear (the_year,the_month)
{
Chooseday (the_year+1,the_month,1);
}

function Showcalender (the_year,the_month,the_day,firstday)
{
var showstr;
var month_day;
var showmonth;
var today;
var TColor;
Today = new Date ();

Switch (the_month)
{
Case 1:showmonth = "January"; Month_day = 31; Break
Case 2:
Showmonth = "February";
if (Runnian (the_year))
Month_day = 29;
Else
Month_day = 28;
Break
Case 3:showmonth = "March"; Month_day = 31; Break
Case 4:showmonth = "April"; Month_day = 30; Break
Case 5:showmonth = "May"; Month_day = 31; Break
Case 6:showmonth = "June"; Month_day = 30; Break
Case 7:showmonth = "July"; Month_day = 31; Break
Case 8:showmonth = "August"; Month_day = 31; Break
Case 9:showmonth = "September"; Month_day = 30; Break
Case 10:showmonth = "October"; Month_day = 31; Break
Case 11:showmonth = "November"; Month_day = 30; Break
Case 12:showmonth = "December"; Month_day = 31; Break

}


Showstr = "";
Showstr = "<table cellpadding=0 cellspacing=0 border=1 bordercolor= #acbad5 width=95% align=center valign=top>";
Showstr + = "<tr><td width=0 style=′cursor:hand′onclick=prevyear (" +the_year+ "," + The_Month + ") ><< &LT;/TD&GT;&LT;TD width=0> "+ the_year +" </td><td width=0 onclick=nextyear ("+The_Year+", "+The_Month+") STYLE=′CURSOR:HAND′&GT;&GT;&GT;&LT;/TD&GT;&LT;TD width=0 style=′cursor:hand′onclick=prevmonth ("+The_Year+", "+The _month+ ") ><<</td><td width=100 align=center>" + showmonth + "</td><td width=0 onclick= Nextmonth ("+the_year+", "+the_month+") style=′cursor:hand′>>></td></tr> ";
Showstr + = "<tr><td align=center width=100% colspan=6>";
Showstr + = "<table cellpadding=2 cellspacing=2 border=2 bordercolor= #fffcff width=100%>";
Showstr + = "<tr align=center bgcolor= #95b8f8 >";
Showstr + = "<td><strong><font color= #daedff > Day </font></strong></td>";
Showstr + = "<td><strong><font color= #daedff > a </font></strong></td>";
Showstr + = "<td><strong><font color= #daedff > Two </font></strong></td>";
Showstr + = "<td><strong><font color= #daedff > Three </font></strong></td>";
Showstr + = "<td><strong><font color= #daedff > Four </font></strong></td>";
Showstr + = "<td><strong><font color= #daedff > Five </font></strong></td>";
Showstr + = "<td><strong><font color= #daedff > Six </font></strong></td>";
Showstr + = "</Tr><tr>";

Alert ("firstday=" +firstday);
for (var i=1; i<=firstday; i++)
Showstr + = "<td align=center bgcolor= #CCCCCC > </Td>";


for (var i=1; i<=month_day; i++)
{
Date control------------------------------------------
if (number (The_month) < 10)
var the_month1 = "0" + the_month;
Else
var the_month1 = The_month;

if (i<10)
var month_day1 = "0" + i;
Else
Month_day1 = i;

var test1 = the_year + "-" +the_month1+ "-" +month_day1;
var thisdate = today.getfullyear () + "-" + (Today.getmonth () +1) + "-" + today.getdate ();

var sdate=thisdate;
var edate=test1;
var sArr = Sdate.split ("-");
var Earr = Edate.split ("-");
var srdate = new Date (sarr[0], sarr[1], sarr[2]);
var erdate = new Date (earr[0], earr[1], earr[2]);
var result = (erdate-srdate)/(24*60*60*1000);

if (result>=1&&result<37)
{
BgColor = "#fc0000";
TColor = "#000000";
Showstr + = "<td align=center style= ' color:" +tcolor+ "' bgcolor=" + bgcolor + "style=′cursor:hand′onclick=getthisdate ( "+ The_year +", "+ The_month +", "+ i +") > "+ i +" </td> ";
}
Date control-------------------------------------------
Else
{
BgColor = "#fbfaf8";
TColor = "#d8dde3";
XX MV
Showstr + = "<td align=center style= ' color:" +tcolor+ "' bgcolor=" + bgcolor + "Style=′cursor:hand′onclick=getthisdat E ("+ The_year +", "+ The_month +", "+ i +") > "+ i +" </td> ";
Showstr + = "<td align=center style= ' color:" +tcolor+ "' bgcolor=" + bgcolor + "style=′cursor:hand′onclick=chooseday (" + The_year + "," + The_month + "," + i + ") >" + i + "</td>";
}

FirstDay = (firstday+1)%7;

if ((firstday==0) && (i!=month_day))
Showstr + = "</tr><tr>";
}

if (firstday!=0)
{
for (i=firstday; i<7; i++)
Showstr + = "<td align=center bgcolor= #CCCCCC > </td>";
Showstr + = "</tr>";
}

Showstr + = "</tr></table></td></tr></table>";
cc.innerhtml = Showstr;

}

</script>

<script language= "JavaScript" >

var the_year,the_day,the_month;
var today;
var FirstDay;
Today = new Date ();
The_year = Today.getfullyear ();
Alert ("the_year=" +the_year);
The_month = Today.getmonth () + 1;
The_day = Today.getdate ();
FirstDay = Getweekday (the_year,the_month);
Showcalender (The_year,the_month,the_day,firstday);
</script>

JavaScript Write Calendar Code

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.