本帖最后由 汪磊 于 2012-12-9 21:59 编辑
以前做博客 时候写的一个周历,感觉还不错 加图片轮播的,需要的可以拿去看看;附一下JS代码:- //计算日期
- function GetDateStr(num) {
- var otherDay = new Date();
- otherDay.setDate(otherDay.getDate() + num);//获取num天后的日期
- var otherY = otherDay.getFullYear();
- var otherM = otherDay.getMonth() + 1;//获取当前月份的日期
- var otherD = otherDay.getDate(/dd|DD/);
- var otherD = (otherD < 10) ? '0' + otherD : otherD;
- var y = document.getElementsByClassName("year")[0];
- var m = document.getElementsByClassName("month")[0];
- y.innerHTML = otherY;
- m.innerHTML = otherM+'月';
- return [otherY, otherM, otherD];
- }
- //写出周历
- function getWeek(n) {
- var w = document.getElementsByClassName("slide-triggers")[0];
- var li = w.children;
- var sun = document.getElementsByClassName("date");
- var d = new Date().getDate();
- var m = -n;
- for (a = 0; a <= 7; a++) {
- sun[a].textContent = GetDateStr(m)[2];
- if (sun[a].textContent == d) { li[a].className = 'on';}
- li[a].title = GetDateStr(m)[0] + '年' + GetDateStr(m)[1] + '月' + GetDateStr(m)[2] + '日';
- m++;
- }
- }
- $(function weekDay() {
- //这里设置轮播的参数
- $(".myweek").slide({ mainCell: ".slide-content ul", titCell: ".slide-triggers li", defaultIndex: day, trigger: "click" })
- //星期判断
- var day = new Date().getDay();
- switch (day) {
- case 1:
- getWeek(1);
- break;
- case 2:
- getWeek(2);
- break;
- case 3:
- getWeek(3);
- break;
- case 4:
- getWeek(4);
- break;
- case 5:
- getWeek(5);
- break;
- case 6:
- getWeek(6);
- break;
- case 0:
- getWeek(0);
- break;
- }
- });
复制代码 |
|