js日期

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="jquery-1.7.2-min.js" charset="utf-8" type="text/javascript"></script>
</head>

<body>
<style>
*{padding:0px;margin:0px;border:0px;}
.c{clear:both}
.w775{width:775px;overflow:hidden;height:27px;overflow:hidden;}
.position_r{position:relative}
.position_a{position: absolute;}
.position_f{position:fixed;}
.center{margin:0px auto;}
.mrt_date{width:936px;border:1px solid #dedede;padding:1px; }
.mrt_date a{width:28px;height:26px; display:inline-block;cursor:pointer;text-align:center;line-height:27px;}
.mrt_date a#mrt_left{float:left;}
.mrt_date a#mrt_right{float:right;}
.mrt_date div.mrt_week{width:876px; font-weight:bold;line-height:27px;display:inline-block;height:27px;background:url(../mrt_images/date_bg_x.jpg) repeat-x;float:left;margin:0 2px;}
.w775 span{display:inline-block;float:left;height:27px; width:25px;text-align:center;}
.w775 div.position_a{width:1134px;left:0px;top:0px;}
span.mrt_weekend{color:#c00000}
#days{margin-left:81px;}
.mrt_date_num{height:30px; line-height:30px;}
.mrt_date_num div.position_a{width:80px;text-align:center;}
</style>
<div class="mrt_date mb10">
<a id="mrt_left"><</a>
<div class="mrt_week">
<div class="center w775 position_r">
<div class="position_a" id="mrt_date">
<span class="mrt_weekend">日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span class="mrt_weekend">六</span>
<span class="mrt_weekend">日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span class="mrt_weekend">六</span>
<span class="mrt_weekend">日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span class="mrt_weekend">六</span>
<span class="mrt_weekend">日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span class="mrt_weekend">六</span>
<span class="mrt_weekend">日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span class="mrt_weekend">六</span>
<span class="mrt_weekend">日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span class="mrt_weekend">六</span>
</div>
</div>
</div>
<a id="mrt_right">></a>
<div class="c"></div>
<div class="mrt_date_num position_r">
<div class="position_a" id="mrt_date2">0000-00</div>
<div class="w775" id="days">
<span class="mrt_weekend">1</span><span class="mrt_weekend">2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span>
<span class="mrt_weekend">8</span><span class="mrt_weekend">9</span><span>10</span><span>11</span><span>12</span><span>13</span><span>14</span>
<span class="mrt_weekend">15</span><span class="mrt_weekend">16</span><span>17</span><span>18</span><span>19</span><span>20</span><span>21</span>
<span class="mrt_weekend">22</span><span class="mrt_weekend">23</span><span>24</span><span>25</span><span>26</span><span>27</span><span>28</span>
<span class="mrt_weekend">29</span><span class="mrt_weekend">30</span><span>31</span>
</div>
</div>
</div>
<script>
var mrtdate = document.getElementById("mrt_date2"),
myDate = new Date(),
i = myDate.getMonth() + 1,
year = myDate.getFullYear(),
day = myDate.getDate(),
weekday = myDate.getDay(),
leapYear, week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");

function getFirstDay(i, n) {
if (i) {
if (n) {
if (n % 4 == 0 && i == 2) {
var days = 29;
var mouth = i
} else {
var days = new Date(myDate.getYear(), i, 0).getDate();
var mouth = i
}
} else {
if (year % 4 == 0 && i == 2) {
var days = 29;
var mouth = i
} else {
var days = new Date(myDate.getYear(), i, 0).getDate();
var mouth = i
}
}
} else {
var mouth = myDate.getMonth() + 1;
if (n) {
if (n % 4 == 0 && mouth == 2) {
var days = 29
} else {
var days = new Date(myDate.getYear(), i, 0).getDate()
}
} else {
if (year % 4 == 0 && mouth == 2) {
var days = 29
} else {
var days = new Date(myDate.getYear(), i, 0).getDate()
}
}
} if (n) {
mrtdate.innerHTML = n + "-" + mouth;
myDate.setFullYear(n)
} else {
mrtdate.innerHTML = year + "-" + mouth
} if (i) {
myDate.setMonth(i - 1)
}
myDate.setDate(1);
var mrt_num = myDate.getDay();
$("#mrt_date").css({
left: -mrt_num * 25 + "px"
});
$("#days").css({
width: days * 25 + "px"
})
}
$(function() {
$("#mrt_left").click(function() {
i--;
if (i == 0) {
year--;
i = 12
}
getFirstDay(i, year)
});
$("#mrt_right").click(function() {
i++;
if (i == 13) {
year++;
i = 1
}
getFirstDay(i, year)
})
});
getFirstDay();

</script>
</body>
</html>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。