分享
 
 
 

JavaScript 实现日历式日期选择

王朝html/css/js·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>Canlender--JavaScript</title>

<style>

td {

font-family: Arial, Helvetica, sans-serif;

font-size: 12px;

}

</style>

</head>

<body>

<table border="0" cellpadding="0" cellspacing="0" width="180">

<tr><td id=cc>

</td></tr></table>

</body>

<script language="JavaScript">

function RunNian(The_Year)

{

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

return true;

else

return false;

}

function GetWeekday(The_Year,The_Month)

{

var Allday;

Allday = 0;

if (The_Year>2000)

{

for (i=2000 ;i<The_Year; i++)

if (RunNian(i))

Allday += 366;

else

Allday += 365;

for (i=2; i<=The_Month; i++)

{

switch (i)

{

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;

}

}

}

return (Allday+6)%7;

}

function chooseday(The_Year,The_Month,The_Day)

{

var Firstday;

var completely_date;

if (The_Day!=0)

completely_date = The_Year + "-" + The_Month + "-" + The_Day;

else

completely_date = "No Choose";

//showdate 只是一个为了显示而采用的东西,

//如果外部想引用这里的时间,可以通过使用 completely_date引用完整日期

//也可以通过The_Year,The_Month,The_Day分别引用年,月,日

//当进行月份和年份的选择时,认为没有选择完整的日期

showdate.innerText = completely_date;

Firstday = GetWeekday(The_Year,The_Month);

ShowCalender(The_Year,The_Month,The_Day,Firstday);

}

function nextmonth(The_Year,The_Month)

{

if (The_Month==12)

chooseday(The_Year+1,1,0);

else

chooseday(The_Year,The_Month+1,0);

}

function prevmonth(The_Year,The_Month)

{

if (The_Month==1)

chooseday(The_Year-1,12,0);

else

chooseday(The_Year,The_Month-1,0);

}

function prevyear(The_Year,The_Month)

{

chooseday(The_Year-1,The_Month,0);

}

function nextyear(The_Year,The_Month)

{

chooseday(The_Year+1,The_Month,0);

}

function ShowCalender(The_Year,The_Month,The_Day,Firstday)

{

var showstr;

var Month_Day;

var ShowMonth;

var today;

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=#999999 width=95% align=center valign=top>";

showstr += "<tr><td width=0 style='cursor:hand' onclick=prevyear("+The_Year+"," + The_Month + ")>&lt;&lt;</td><td width=0>&nbsp;" + The_Year + "&nbsp;</td><td width=0 onclick=nextyear("+The_Year+","+The_Month+") style='cursor:hand'>&gt;&gt;</td><td width=0 style='cursor:hand' onclick=prevmonth("+The_Year+","+The_Month+")>&lt;&lt;</td><td width=100 align=center>" + ShowMonth + "</td><td width=0 onclick=nextmonth("+The_Year+","+The_Month+") style='cursor:hand'>&gt;&gt;</td></tr>";

showstr += "<tr><td align=center width=100% colspan=6>";

showstr += "<table cellpadding=0 cellspacing=0 border=1 bordercolor=#999999 width=100%>";

showstr += "<Tr align=center bgcolor=#999999> ";

showstr += "<td><strong><font color=#0000CC>日</font></strong></td>";

showstr += "<td><strong><font color=#0000CC>一</font></strong></td>";

showstr += "<td><strong><font color=#0000CC>二</font></strong></td>";

showstr += "<td><strong><font color=#0000CC>三</font></strong></td>";

showstr += "<td><strong><font color=#0000CC>四</font></strong></td>";

showstr += "<td><strong><font color=#0000CC>五</font></strong></td>";

showstr += "<td><strong><font color=#0000CC>六</font></strong></td>";

showstr += "</Tr><tr>";

for (i=1; i<=Firstday; i++)

showstr += "<Td align=center bgcolor=#CCCCCC>&nbsp;</Td>";

for (i=1; i<=Month_Day; i++)

{

if ((The_Year==today.getYear()) && (The_Month==today.getMonth()+1) && (i==today.getDate()))

bgColor = "#FFCCCC";

else

bgColor = "#CCCCCC";

if (The_Day==i) bgColor = "#FFFFCC";

showstr += "<td align=center 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>&nbsp;</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.getYear();

The_Month = today.getMonth() + 1;

The_Day = today.getDate();

Firstday = GetWeekday(The_Year,The_Month);

ShowCalender(The_Year,The_Month,The_Day,Firstday);

</script>

<div id=showdate></div>

</html>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有