分享
 
 
 

javascript写的小日历

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

var text;

var flag = 0;

var cx=0;

var cy=0;

var val=0;

var running=false;

var stx,sty;

function locate()

{ cx=window.event.x;

cy=window.event.y;

}

document.onmousemove=locate;

function mousemove(){

var x,y;

x=cx-stx;

y=cy-sty;

if(x<0) {x=0;}

if(y<0) {y=0;}

with(calendar.style)

{

left=x.toString()+"px";

top=y.toString()+"px";

}

}

function mousedown(){

with(calendar.style)

{

stx=cx-parseInt(left.substring(0,left.charAt('p')+1));

sty=cy-parseInt(top.substring(0,top.charAt('p')+1));

}

if(!running){

val=setInterval("mousemove()",10);

running=true;

}

else{

clearInterval(val);

running=false;

}

}

function mouseup(){

if(running){

clearInterval(val);

running=false;

}

}

function MakeCal(date,intCount) {

var z1, z2,blntoday

var today = new Date();

if (date == null) {

var szMonth = today.getMonth();

var szYear = today.getFullYear();

var szDate = today.getDate();

}

else {

z1 = date.indexOf("/");

z2 = date.indexOf("/", 3);

var szMonth = Number(date.slice(0,z1)) - 1;

var szYear = Number(date.slice(z2 + 1, z2+ 5));

if(szMonth < 0){

szMonth = 11;

szYear = szYear - 1;

}

else if(szMonth > 11){

szMonth = 0;

szYear = szYear + 1;

}

var szDate = Number(date.slice(z1 + 1,z2));

}

var x, intTemp, szId, max, todayx, startx;

var szStart = new Date(szYear, szMonth, 1);

var intDay = szStart.getDay();

var blSet = false;

var szCal;

szStart.setMonth(szMonth - 1);

var PrevMonth = szStart.getMonth();

var PrevYear = szStart.getFullYear();

szStart = new Date(szYear, szMonth, 1);

szStart.setMonth(szMonth + 1);

var NextMonth = szStart.getMonth();

var NextYear = szStart.getFullYear();

szStart = new Date(szYear, szMonth, 1);

szCal = "" ;

szCal = szCal + "<table id=tblBor width=100% border=0 bgcolor=#D6C7DA style=\"border-style:solid;border-width:1px;border-color:black\" cellspacing=0 cellpadding=0 align='center'><tr><td>";

szCal = szCal + "<table id=tblCal width=100% border=0 bgcolor=#E7EAE6 style=\"cursor:default;\" cellspacing=0 cellpadding=3 >";

if (szStart.getMonth() == (szMonth))

szCal = szCal + "<tr bgcolor=#BDE6E8 onmouseup=\"mouseup();\" onmousedown=\"mousedown()\"><td colspan=6 align=center id=title style=\"cursor:default;\"><div style=\"display:none;\" id=\"whoactive\">"+MakeString(szStart.getMonth())+"10</div>" +"<font color=#00009F>"+ MakeStringT(szMonth)+"</Font>" + " " +"<Font Color =#00009F>"+ szYear + "年"+"</font>"+"</td><td><input type=button value=&times style=\"background-color: #DFECEC; width: 18; height: 18\" onclick=\"calendar.style.visibility='hidden'\"></td></tr>";

else

szCal = szCal + "<tr bgcolor=#BDE6E8 onmouseup=\"mouseup();\" onmousedown=\"mousedown()\"><td colspan=6 align=center id=title style=\"cursor:default;\"><div style=\"display:none;\" id=\"whoactive\">"+MakeString(szStart.getMonth())+"10</div>" +"<font color=#7F7F7F>"+ MakeStringT(szMonth)+"</Font>" + " " +"<Font Color =#7F7F7F>"+ szYear + "年"+"</font>"+"</td><td><input type=button value=&times style=\"background-color: #DFECEC; width: 18; height: 18\" onclick=\"calendar.style.visibility='hidden'\"></td></tr>";

szCal = szCal + "<tr id=rowTitle style=\"cursor:default;\"><td><font color=#53A46B>日</font></td><td><font color=#0A13C0>一</font></td><td><font color=#0A13C0>二</font></td><td><font color=#0A13C0>三</font></td><td><font color=#0A13C0>四</font></td><td><font color=#0A13C0>五</font></td><td><font color=#53A46B>六</font></td></tr>";

for (x=1; x<43; x++) {

if (x % 7 == 1) {

szCal = szCal + "<tr>"

}

szStart = new Date(szYear, szMonth, 1);

intTemp = (-(intDay - x));

szStart.setDate(intTemp);

szId = MakeString(szStart.getMonth()) + x;

if (!blSet) {

if (szStart.getMonth() == (szMonth + 1)) {

blSet = true;

max = x;

}

if (szStart.getFullYear() == (szYear + 1)) {

blSet = true;

max = x;

}

}

blntoday = 0;

if (szStart.getDate() == today.getDate()) {

if (szStart.getMonth() == today.getMonth()) {

if (szStart.getYear() == today.getYear()) {

todayx = x;

blntoday = 1;

}

}

}

szCal = szCal + "<td ";

if(intCount == 0){

if (szStart.getMonth() == (szMonth)) {

if (szStart.getDate() == today.getDate()) {

szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','0');document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';\"";

}

else

{

szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','0');document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';this.style.backgroundColor=\'#aaaaaa\';whoactive.innerHTML=this.id;\"";

}

}

else {

szCal = szCal + "onclick=\"MakeCal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','0')\"";

}

}

if(intCount == 1){

if (szStart.getMonth() == (szMonth)) {

if (szStart.getDate() == today.getDate()) {

szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','1')document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';\"";

}

else

{

szCal = szCal + "onclick=\"setVal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','1');document.getElementById(whoactive.innerHTML).style.backgroundColor=\'#E7EAE6\';this.style.backgroundColor=\'#aaaaaa\';whoactive.innerHTML=this.id;\"";

}

}

else {

szCal = szCal + "onclick=\"MakeCal('" + (szStart.getMonth() + 1 ) + "/" + szStart.getDate() + "/" + szStart.getFullYear() + "','1')\"";

}

}

if (blntoday == 1)

szCal = szCal + " id=" + szId + "><center><font color = Yellow>" + szStart.getDate() + "</font></td>";

else

szCal = szCal + " id=" + szId + "><center>" + szStart.getDate() + "</td>";

if (x % 7 == 0) {

szCal = szCal + "</tr>"

}

}

szCal = szCal + "</tr>";

szCal = szCal + "</table></td></tr>";

szCal = szCal + "<tr align=center><td><table border=0 bgcolor=#BDE6E8 width=100% cellspacing=0 cellpadding=3>";

szCal = szCal + "<tr>";

if(intCount == 0){

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + (PrevMonth + 2) + "/1/" + (PrevYear - 1) + "','0')\"><font face=webdings>7</font></a></td>";

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + (PrevMonth + 1) + "/1/" + PrevYear + "','0')\"><font face=webdings>3</font></a></td>";

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + (NextMonth + 1) + "/1/" + NextYear + "','0')\"><font face=webdings>4</font></a></td>";

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + NextMonth + "/1/" + (NextYear + 1) + "','0')\"><font face=webdings>8</font></a></td>";

}

if(intCount == 1){

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + (PrevMonth + 2) + "/1/" + (PrevYear - 1) + "','1')\"><font face=webdings>7</font></a></td>";

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + (PrevMonth + 1) + "/1/" + PrevYear + "','1')\"><font face=webdings>3</font></a></td>";

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + (NextMonth + 1) + "/1/" + NextYear + "','1')\"><font face=webdings>4</font></a></td>";

szCal = szCal + "<td align=center style=\"cursor:hand;\"><a onclick=\"MakeCal('" + NextMonth + "/1/" + (NextYear + 1) + "','1')\"><font face=webdings>8</font></a></td>";

}

szCal = szCal + "</tr></table>";

szCal = szCal + "</td></tr></table>";

calendar.innerHTML = szCal;

for (x=intDay; x>0; x--) {

eval(MakeString(PrevMonth) + x + ".style.color = \"909090\"")

}

for (x=max; x<43; x++) {

eval(MakeString(NextMonth) + x + ".style.color = \"909090\"")

}

if (szMonth == today.getMonth()) {

if (szYear == today.getFullYear()) {

eval(MakeString(szMonth) + todayx + ".style.backgroundColor = \"#7F7F7F\"");

eval(MakeString(szMonth) + todayx + ".style.Color = \"yellow\"");

}

}

tblCal.style.color = "#00009F";

tblCal.style.fontFamily = "arial";

tblCal.style.cursor = "hand";

tblCal.style.fontSize = "10";

rowTitle.style.backgroundColor = "#BBD1EA";

//event.cancelBubble = true;

}

function MakeString(intMonth) {

var Month

switch (intMonth) {

case 0 :

Month = "JANUARY";

break;

case 1 :

Month = "FEBUARY";

break;

case 2 :

Month = "MARCH";

break;

case 3 :

Month = "APRIL";

break;

case 4 :

Month = "MAY";

break;

case 5 :

Month = "JUNE";

break;

case 6 :

Month = "JULY";

break;

case 7 :

Month = "AUGUST";

break;

case 8 :

Month = "SEPTEMBER";

break;

case 9 :

Month = "OCTOBER";

break;

case 10 :

Month = "NOVEMBER";

break;

case 11 :

Month = "DECEMBER";

}

return (Month);

}

function MakeStringT(intMonth) {

var Month

switch (intMonth) {

case 0 :

Month = "一月";

break;

case 1 :

Month = "二月";

break;

case 2 :

Month = "三月";

break;

case 3 :

Month = "四月";

break;

case 4 :

Month = "五月";

break;

case 5 :

Month = "六月";

break;

case 6 :

Month = "七月";

break;

case 7 :

Month = "八月";

break;

case 8 :

Month = "九月";

break;

case 9 :

Month = "十月";

break;

case 10 :

Month = "十一月";

break;

case 11 :

Month = "十二月";

}

return (Month);

}

function keepCal() {

event.cancelBubble = true;

}

function public_get_txtDate() {

return txtDate;

}

function public_get_value() {

return txtDate.value;

}

function getCal(intCount){

today=new Date();

nowyear=today.getYear();

nowmonth=today.getMonth()+1;

nowday=today.getDate();

currdate = nowmonth+'/'+nowday+'/'+nowyear;

MakeCal(currdate, 0)

intFlag = 1;

//calendar.style.left = iLeft;

//calendar.style.top = iTop;

calendar.style.visibility = 'visible';

//event.cancelBubble = true;

}

function setVal(date, intCount){

z1 = date.indexOf("/");

z2 = date.indexOf("/", 3);

var szMonth = date.slice(0,z1);

if (szMonth.length<2)

szMonth="0"+szMonth;

var szYear = date.slice(z2 + 1, z2+ 5);

/*

if(szMonth < 0){

szMonth = 11;

szYear = szYear - 1;

}

else if(szMonth > 11){

szMonth = 0;

szYear = szYear + 1;

}

*/

var szDate = date.slice(z1 + 1,z2);

if (szDate.length<2)

szDate = "0"+szDate;

text.value=szYear+'-'+szMonth+'-'+szDate;

calendar.style.display='none'

}

function hideCal(){

calendar.style.visibility = 'hidden';

}

function show_calendar()

{

calendar.style.visibility='hidden'

//calendar.style.visibility='display'

}

function show_cal(get_time)

{

if(event.clientX+163> document.body.clientWidth)

calendar.style.left=event.clientX+document.body.scrollLeft-150;

else calendar.style.left=event.clientX+document.body.scrollLeft;

if(event.clientY+200 > document.body.clientHeight)

calendar.style.top=event.clientY+document.body.scrollTop-200;

else calendar.style.top=event.clientY+document.body.scrollTop;

//calendar.style.left=event.clientX;

//calendar.style.top=event.clientY;

calendar.style.visibility='visible';

MM_showHideLayers('calendar','','show')

calendar.style.display='list-item';

text=get_time;

flag=1;

return false;

}

//document.onclick = hideCal;

function MM_findObj(n, d) { //v4.0

var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

if(!x && document.getElementById) x=document.getElementById(n); return x;

}

function MM_showHideLayers() { //v3.0

var i,p,v,obj,args=MM_showHideLayers.arguments;

for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];

if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }

obj.visibility=v; }

}

function hide_cal()

{

if (flag==1)

{

flag=0;

if(!calendar.focus())

calendar.style.display='none'

}

return false;

}

程序调用页面代码:

<html>

<head>

....................

</head>

<SCRIPT src="cal.js"></SCRIPT>

<body MS_POSITIONING="GridLayout">

<DIV id=calendar onmouseover=keepCal()

style="DISPLAY: none; Z-INDEX: 1; LEFT: 0px; VISIBILITY: hidden; OVERFLOW: visible; WIDTH: 150px; POSITION: absolute; TOP: 100px; HEIGHT: 225px"

name="calendar">

<SCRIPT language=javascript>getCal(0);</SCRIPT>

</DIV>

<body>

.............................................................

<input onclick=show_cal(this) readOnly size=12 name=startdate>

至 <input onclick=show_cal(this) readOnly size=12 name=enddate>

.........................................

</body>

</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- 王朝網路 版權所有