根据一篇js日历插件改写的
2020-11-15 04:37
标签:com http blog style class div img code java size javascript 根据一篇js日历插件改写的,布布扣,bubuko.com 根据一篇js日历插件改写的 标签:com http blog style class div img code java size javascript 原文地址:http://www.cnblogs.com/xiaojingjing/p/3696739.html 1
4
5 DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
7 html xmlns="http://www.w3.org/1999/xhtml">
8
9 head>
10
11 script src="date.js" language="javascript" >script>
12
13 head>
14
15 body>
16
17 input type="text" style="width:70px" onfocus="HS_setDate(this)">
18
19
20
21
22 body>
23
24 html>
25
26
27 //date.js
28
29
30 function HS_DateAdd(interval,number,date){
31
32 number = parseInt(number);
33
34 if (typeof(date)=="string"){var date = new Date(date.split("-")[0],date.split("-")[1],date.split("-")[2])}
35
36 if (typeof(date)=="object"){var date = date}
37
38 switch(interval){
39
40 case "y":return new Date(date.getFullYear()+number,date.getMonth(),date.getDate()); break;
41
42 case "m":return new Date(date.getFullYear(),date.getMonth()+number,checkDate(date.getFullYear(),date.getMonth()+number,date.getDate())); break;
43
44 case "d":return new Date(date.getFullYear(),date.getMonth(),date.getDate()+number); break;
45
46 case "w":return new Date(date.getFullYear(),date.getMonth(),7*number+date.getDate()); break;
47
48 }
49
50 }
51
52 function checkDate(year,month,date){
53
54 var enddate = ["31","28","31","30","31","30","31","31","30","31","30","31"];
55
56 var returnDate = "";
57
58 if (year%4==0){enddate[1]="29"}
59
60 if (date>enddate[month]){returnDate = enddate[month]}else{returnDate = date}
61
62 return returnDate;
63
64 }
65
66 function WeekDay(date){
67
68 var theDate;
69
70 if (typeof(date)=="string"){theDate = new Date(date.split("-")[0],date.split("-")[1],date.split("-")[2]);}
71
72 if (typeof(date)=="object"){theDate = date}
73
74 return theDate.getDay();
75
76 }
77
78 function HS_calender(){
79
80 var lis = "";
81
82 var style = "";
83
84
85
86 style +="style type=‘text/css‘>";
87
88 style +=".calender { width:170px; height:auto; font-size:12px; margin-right:14px; background:url(calenderbg.gif) no-repeat right center #fff; border:1px solid #397EAE; padding:1px;z-index:10009;}";
89
90 style +=".calender ul {list-style-type:none; margin:0; padding:0;}";
91
92 style +=".calender .day { background-color:#EDF5FF; height:20px;}";
93
94 style +=".calender .day li,.calender .date li{ float:left; width:14%; height:20px; line-height:20px; text-align:center}";
95
96 style +=".calender li a { text-decoration:none; font-family:Tahoma; font-size:11px; color:#333}";
97
98 style +=".calender li a:hover { color:#f30; text-decoration:underline}";
99
100 style +=".calender li a.hasArticle {font-weight:bold; color:#f60 !important}";
101
102 style +=".lastMonthDate, .nextMonthDate {color:#bbb;font-size:11px}";
103
104 style +=".selectThisYear a, .selectThisMonth a{text-decoration:none; margin:0 2px; color:#000; font-weight:bold}";
105
106 style +=".calender .LastMonth, .calender .NextMonth{ text-decoration:none; color:#000; font-size:18px; font-weight:bold; line-height:16px;}";
107
108 style +=".calender .LastMonth { float:left;}";
109
110 style +=".calender .NextMonth { float:right;}";
111
112 style +=".calenderBody {clear:both}";
113
114 style +=".calenderTitle {text-align:center;height:20px; line-height:20px; clear:both}";
115
116 style +=".today { background-color:#ffffaa;border:1px solid #f60; padding:2px}";
117
118 style +=".today a { color:#f30; }";
119
120 style +=".calenderBottom {clear:both; border-top:1px solid #ddd; padding: 3px 0; text-align:left;line-height:20px}";
121
122 style +=".calenderBottom a {text-decoration:none; margin:2px !important; font-weight:bold; color:#000}";
123
124 style +=".calenderBottom a.closeCalender{float:right;}";
125
126 style +=".closeCalenderBox {float:right; border:1px solid #000; background:#fff; font-size:9px; width:11px; height:11px; line-height:11px; text-align:center;overflow:hidden; font-weight:normal !important}";
127
128 style +="style>";
129
130 var now;
131
132 if (typeof(arguments[0])=="string"){
133
134 selectDate = arguments[0].split("-");
135
136 var year = selectDate[0];
137
138 var month = parseInt(selectDate[1])-1+"";
139
140 var date = selectDate[2];
141
142 now = new Date(year,month,date);
143
144 }else if (typeof(arguments[0])=="object"){
145
146 now = arguments[0];
147
148 }
149
150
151
152 var lastMonthEndDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+now.getMonth()+"-01").getDate();
153
154 var lastMonthDate = WeekDay(now.getFullYear()+"-"+now.getMonth()+"-01");
155
156 var thisMonthLastDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-01");
157
158 var thisMonthEndDate = thisMonthLastDate.getDate();
159
160 var thisMonthEndDay = thisMonthLastDate.getDay();
161
162 var todayObj = new Date();
163
164 today = todayObj.getFullYear()+"-"+todayObj.getMonth()+"-"+todayObj.getDate();
165
166 for (i=0; ilastMonthDate; i++){ // Last Month‘s Date
167
168 lis = "