jquery 农历日历 可自适应

jquery 农历日历 可自适应

在网上找了许多大牛做的农历日历,但是不是不符合项目中的要求,就是本身就有问题有Bug ,把大牛门的做日历看了n遍 自己又改造了一遍得到了这个:随后日历又要做个自适应的长宽,又在js中改造代码。。。。。。 也感谢大牛门的代码 不说了 上代码:

前台:

<table cellpadding="" cellspacing="" id="CalendarTab">
<tr>
<td>
<div id="cal">
<div id="top">
公元<select></select> 年 <select></select>月 农历 <span></span>年 [ <span></span>年 ]
<input type="button" value="回到今天" title="点击后跳转回 今天" style="padding:0px">
</div>
<ul id="wk">
<li>一</li>
<li>二</li>
<li>三</li>
<li>四</li>
<li>五</li>
<li><b>六</b></li>
<li><b>日</b></li>
</ul>
<div id="cm"></div>
</div>
</td>
</tr>
</table>
<script src="~/Scripts/Fullcalendar/LunarClaend.js"></script>

css

/*日历*/
#CalendarTab{width:%}
#cal {width: %; border: ;font-size: 12px;text-align:center;}
#cal #top { height: 28px; line-height: 31px;background: #e7eef8; color: #;}
#cal #top select { font-size: 14px;}
#cal #top input { padding: ;}
#cal ul#wk {margin: ;padding: ;height: 25px;width:%}
#cal ul#wk li {float: left; width: %;line-height: 35px;list-style: none;}
#cal ul#wk li b {font-weight: normal; color: #c60b02;}
#cal #cm { clear: left; border-top: 1px solid #ddd; position: relative;}
#cal #cm .cell {position: absolute;line-height:12px;width:%}
#cal #cm .cell .so {font: bold 18px arial;}

-----------------------

LunarClaend.js

(function () {
var S = navigator.userAgent.indexOf("MSIE") != - && !window.opera;
function M(C) {
return document.getElementById(C)
} function R(C) {
return document.createElement(C)
} var P = [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ];
var K = "甲乙丙丁戊己庚辛壬癸";
var J = "子丑寅卯辰巳午未申酉戌亥";
var O = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
var L = ["小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"];
var D = [, , , , , , , , , , , , , , , , , , , , , , , ];
var B = "日一二三四五六七八九十";
var H = ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"];
var E = "初十廿卅";
//"---"被和谐了 。。。。。。
var V = {
"": "*1元旦节", "": "情人节", "": "学雷锋纪念日", "": "妇女节", "": "植树节", "": "消费者权益日", "": "愚人节", "": "*1劳动节", "": "青年节", "": "国际儿童节", "": "---", "": "建军节", "": "中国教师节", "": "*3国庆节", "": "平安夜", "": "圣诞节"
};
var T = {
"": "*2春节", "": "元宵节", "": "*1端午节", "": "*1中秋节", "": "重阳节", "": "腊八节", "": "除夕"
};
function U(Y) {
function c(j, i) {
var h = new Date((31556925974.7 * (j - ) + D[i] * ) + Date.UTC(, , , , ));
return (h.getUTCDate())
} function d(k) {
var h, j = ;
for (h = ; h > ; h >>= ) {
j += (P[k - ] & h) ? :
} return (j + b(k))
} function a(h) {
return (K.charAt(h % ) + J.charAt(h % ))
} function b(h) {
if (g(h)) {
return ((P[h - ] & ) ? : )
} else {
return ()
}
} function g(h) {
return (P[h - ] & )
} function e(i, h) {
return ((P[i - ] & ( >> h)) ? : )
} function C(m) {
var k, j = , h = ;
var l = new Date(, , );
var n = (m - l) / ;
this.dayCyl = n + ;
this.monCyl = ;
for (k = ; k < && n > ; k++) {
h = d(k);
n -= h;
this.monCyl +=
} if (n < ) {
n += h;
k--;
this.monCyl -=
} this.year = k;
this.yearCyl = k - ;
j = g(k);
this.isLeap = false;
for (k = ; k < && n > ; k++) {
if (j > && k == (j + ) && this.isLeap == false) {
--k;
this.isLeap = true;
h = b(this.year)
} else {
h = e(this.year, k)
} if (this.isLeap == true && k == (j + )) {
this.isLeap = false
} n -= h;
if (this.isLeap == false) {
this.monCyl++
}
} if (n == && j > && k == j + ) {
if (this.isLeap) {
this.isLeap = false
} else {
this.isLeap = true;
--k;
--this.monCyl
}
} if (n < ) {
n += h;
--k;
--this.monCyl
} this.month = k;
this.day = n +
} function G(h) {
return h < ? "" + h : h
} function f(i, j) {
var h = i;
return j.replace(/dd?d?d?|MM?M?M?|yy?y?y?/g, function (k) {
switch (k) {
case "yyyy": var l = "" + h.getFullYear();
return l.substring(l.length - );
case "dd": return G(h.getDate());
case "d": return h.getDate().toString();
case "MM": return G((h.getMonth() + ));
case "M": return h.getMonth() +
}
})
} function Z(i, h) {
var j;
switch (i, h) {
case : j = "初十";
break;
case : j = "二十";
break;
case : j = "三十";
break;
default: j = E.charAt(Math.floor(h / ));
j += B.charAt(h % )
} return (j)
} this.date = Y;
this.isToday = false;
this.isRestDay = false;
this.solarYear = f(Y, "yyyy");
this.solarMonth = f(Y, "M");
this.solarDate = f(Y, "d");
this.solarWeekDay = Y.getDay();
this.solarWeekDayInChinese = "星期" + B.charAt(this.solarWeekDay);
var X = new C(Y);
this.lunarYear = X.year;
this.shengxiao = O.charAt((this.lunarYear - ) % );
this.lunarMonth = X.month;
this.lunarIsLeapMonth = X.isLeap;
this.lunarMonthInChinese = this.lunarIsLeapMonth ? "闰" + H[X.month - ] : H[X.month - ];
this.lunarDate = X.day;
this.showInLunar = this.lunarDateInChinese = Z(this.lunarMonth, this.lunarDate);
if (this.lunarDate == ) {
this.showInLunar = this.lunarMonthInChinese + "月"
} this.ganzhiYear = a(X.yearCyl);
this.ganzhiMonth = a(X.monCyl);
this.ganzhiDate = a(X.dayCyl++);
this.jieqi = "";
this.restDays = ;
if (c(this.solarYear, (this.solarMonth - ) * ) == f(Y, "d")) {
this.showInLunar = this.jieqi = L[(this.solarMonth - ) * ]
} if (c(this.solarYear, (this.solarMonth - ) * + ) == f(Y, "d")) {
this.showInLunar = this.jieqi = L[(this.solarMonth - ) * + ]
} if (this.showInLunar == "清明") {
this.showInLunar = "清明节";
this.restDays =
} this.solarFestival = V[f(Y, "MM") + f(Y, "dd")];
if (typeof this.solarFestival == "undefined") {
this.solarFestival = ""
} else {
if (/\*(\d)/.test(this.solarFestival)) {
this.restDays = parseInt(RegExp.$);
this.solarFestival = this.solarFestival.replace(/\*\d/, "")
}
} this.showInLunar = (this.solarFestival == "") ? this.showInLunar : this.solarFestival;
this.lunarFestival = T[this.lunarIsLeapMonth ? "" : G(this.lunarMonth) + G(this.lunarDate)];
if (typeof this.lunarFestival == "undefined") {
this.lunarFestival = ""
} else {
if (/\*(\d)/.test(this.lunarFestival)) {
this.restDays = (this.restDays > parseInt(RegExp.$)) ? this.restDays : parseInt(RegExp.$);
this.lunarFestival = this.lunarFestival.replace(/\*\d/, "")
}
} if (this.lunarMonth == && this.lunarDate == e(this.lunarYear, )) {
this.lunarFestival = T[""];
this.restDays =
} this.showInLunar = (this.lunarFestival == "") ? this.showInLunar : this.lunarFestival;
// this.showInLunar = (this.showInLunar.length > 4) ? this.showInLunar.substr(0,3) + "..." : this.showInLunar
} var Q = (function () {
var X = {
};
X.lines = ;
X.dateArray = new Array();
function Y(a) {
return (((a % === ) && (a % !== )) || (a % === ))
} function G(a, b) {
return [, (Y(a) ? : ), , , , , , , , , , ][b]
} function C(a, b) {
a.setDate(a.getDate() + b);
return a
} function Z(a) {
var f = ;
var c = new U(new Date(a.solarYear, a.solarMonth - , ));
var d = (c.solarWeekDay - == -) ? : c.solarWeekDay - ;
X.lines = Math.ceil((d + G(a.solarYear, a.solarMonth - )) / );
for (var e = ; e < X.dateArray.length; e++) {
if (c.restDays != ) {
f = c.restDays
} if (f > ) {
c.isRest = true
} if (d-- > || c.solarMonth != a.solarMonth) {
X.dateArray[e] = null;
continue
} var b = new U(new Date());
if (c.solarYear == b.solarYear && c.solarMonth == b.solarMonth && c.solarDate == b.solarDate) {
c.isToday = true
} X.dateArray[e] = c;
c = new U(C(c.date, ));
f--
}
} return {
init: function (a) {
Z(a)
}, getJson: function () {
return X
}
}
})();
var W = (function () {
var C = M("top").getElementsByTagName("SELECT")[];
var X = M("top").getElementsByTagName("SELECT")[];
var G = M("top").getElementsByTagName("SPAN")[];
var c = M("top").getElementsByTagName("SPAN")[];
var Y = M("top").getElementsByTagName("INPUT")[];
function a(g) {
G.innerHTML = g.ganzhiYear;
c.innerHTML = g.shengxiao
} function b(g) {
C[g.solarYear - ].selected = true;
X[g.solarMonth - ].selected = true
} function f() {
var j = C.value;
var g = X.value;
var i = new U(new Date(j, g - , ));
Q.init(i);
N.draw();
if (this == C) {
i = new U(new Date(j, , ));
G.innerHTML = i.ganzhiYear;
c.innerHTML = i.shengxiao
} var h = new U(new Date());
Y.style.visibility = (j == h.solarYear && g == h.solarMonth) ? "hidden" : "visible"
} function Z() {
var g = new U(new Date());
a(g);
b(g);
Q.init(g);
N.draw();
Y.style.visibility = "hidden"
} function d(k, g) {
for (var j = ; j < ; j++) {
var h = R("OPTION");
h.value = j;
h.innerHTML = j;
if (j == k) {
h.selected = "selected"
} C.appendChild(h)
} for (var j = ; j < ; j++) {
var h = R("OPTION");
h.value = j;
h.innerHTML = j;
if (j == g) {
h.selected = "selected"
} X.appendChild(h)
} C.onchange = f;
X.onchange = f
} function e(g) {
d(g.solarYear, g.solarMonth);
G.innerHTML = g.ganzhiYear;
c.innerHTML = g.shengxiao;
Y.onclick = Z;
Y.style.visibility = "hidden"
} return {
init: function (g) {
e(g)
}, reset: function (g) {
b(g)
}
}
})();
var N = (function () {
function C() {
var Z = Q.getJson();
var c = Z.dateArray;
var Wid = $("#CalendarTab").width(); M("cm").style.height = Z.lines * + + "px";
M("cm").innerHTML = "";
for (var a = ; a < c.length; a++) {
if (c[a] == null) {
continue
} var X = R("DIV");
if (c[a].isToday) {
X.style.border = "1px solid #a5b9da";
X.style.background = "#c1d9ff"
} X.className = "cell";
X.style.left = (a % ) * (Wid/7.4) + "px";
X.style.top = Math.floor(a / ) * + + "px"; var b = R("DIV");
b.className = "so";
b.style.color = ((a % ) > || c[a].isRest) ? "#c60b02" : "#313131";
b.innerHTML = c[a].solarDate;
X.appendChild(b);
var Y = R("DIV");
Y.style.color = "#666";
var NInLunar = c[a].showInLunar
var newshowInLunar = "";
if (NInLunar.length>) {
newshowInLunar = NInLunar.substr(, ) + "..."
}
else{newshowInLunar=c[a].showInLunar}
Y.innerHTML = newshowInLunar;
Y.title = c[a].showInLunar;
X.appendChild(Y);
X.onmouseover = (function (d) {
return function (f) {
F.show({
dateIndex: d, cell: this
})
}
})(a);
X.onmouseout = function () {
F.hide()
};
M("cm").appendChild(X)
} var G = R("DIV");
M("cm").appendChild(G);
F.init(G)
} return {
draw: function (G) {
C(G)
}
}
})();
var F = (function () {
var C;
function Y(e, c) {
if (arguments.length > ) {
var b = /([.*+?^=!:${}()|[\]\/\\])/g, Z = "{".replace(b, "\\$1"), d = "}".replace(b, "\\$1");
var a = new RegExp("#" + Z + "([^" + Z + d + "]+)" + d, "g");
if (typeof (c) == "object") {
return e.replace(a, function (f, h) {
var g = c[h];
return typeof (g) == "undefined" ? "" : g
})
}
} return e
} function G(b) {
var a = Q.getJson().dateArray[b.dateIndex];
var Z = b.cell;
if (a.solarFestival != "" || a.lunarFestival != "" || a.jieqi != "") { }
C.style.top = Z.offsetTop + Z.offsetHeight - + "px";
C.style.left = Z.offsetLeft + Z.offsetWidth - + "px";
C.style.display = "block"
} function X() {
C.style.display = "none"
} return {
show: function (Z) {
G(Z)
}, hide: function () {
X()
}, init: function (Z) {
C = Z
}
}
})();
var A = new U(new Date());
if (S) {
window.attachEvent("onload", function () {
W.reset(A)
})
} W.init(A);
Q.init(A);
N.draw();
})();

http://www.51xuediannao.com/js/texiao/rili.html

上一篇:Java课程设计----仿Windows标准型计算器


下一篇:Scut:Redis 资源管理器