惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
小众软件
小众软件
The Last Watchdog
The Last Watchdog
Latest news
Latest news
P
Palo Alto Networks Blog
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
P
Privacy International News Feed
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
T
Threatpost
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
Spread Privacy
Spread Privacy
T
Tor Project blog
Cyberwarzone
Cyberwarzone
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
S
Securelist
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
CERT Recently Published Vulnerability Notes
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
A
Arctic Wolf
腾讯CDC
WordPress大学
WordPress大学
IT之家
IT之家
Last Week in AI
Last Week in AI
博客园 - 聂微东
P
Proofpoint News Feed
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Help Net Security
Help Net Security
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
美团技术团队
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Tailwind CSS Blog

博客园 - 痴人说梦

批量清除数据库中被植入的垃圾信息 解决Windows Server2008R2中导入Excel不能使用Jet 4.0 asp.net(C#) 远程获取网页内容代码分享 JavaScript有关的10个怪癖和秘密 js javascript 鼠标控制图片左右滚动带自动翻滚,图片滑动新闻展示 - 痴人说梦 asp.net2.0邮箱发送代码 JS解析,格式化日期 JavaScript 实用脚本,很好,珍藏起来[转贴] WinForms / 23个.NET开源项目 使用js获取QueryString的方法小结 js实现图片高清晰等比缩小 ASP.NET使用NPOI类库导出Excel jQuery获取Select选择的Text和 Value(转) - 痴人说梦 - 博客园 IT项目管理工具总结 - 痴人说梦 - 博客园 有关类及类之间,类成员代码执行顺序链接 window.opener 的用法 用js进行url编码后用php反解以及用php实现js的escape功能函数总结 JS得到当前鼠标的位置 div定位 鼠标放在按钮上显示层提示 - 痴人说梦 - 博客园
JCalendar 日历控件
痴人说梦 · 2010-01-30 · via 博客园 - 痴人说梦

/***************************
 *JCalendar日历控件
 *@author xx
 *@date 2010-1-30
 ***************************/

/*
 *@param year 年份
 *@param month 月份

 *@param date 日期

*@id 控件触发显示日历的id

 */
 /*如果参数不足三个那么就初始化为当天日期*/
function JCalendar (id,year,month,date) {
    var _date = arguments.length == 1 ? new Date() : new Date(year,month-1,date);

    //实例变量
//    this.id=id;
    this.year = _date.getFullYear();
    this.month = _date.getMonth() + 1;
    this.fday = new Date(this.year,this.month-1,1).getDay();//每月第一天的前一天星期数
    this.dayNum = new Date(this.year,this.month,0).getDate();//每月的天数
    //成员变量,当前年月日
    JCalendar.cur_year = this.year;
    JCalendar.cur_month = this.month;
    JCalendar.cur_date = _date.getDate();
    JCalendar._id=id;
}
JCalendar.prototype.show = function(){
    
    var date = new Array(this.fday > 0 ? this.day : 0);//预先定义一段空数组,对应日历里第一周空的位置
    var html_str = new Array();
    var date_index = 0;
    var weekDay = ["日","一","二","三","四","五","六"];
    for(var j = 1; j <= this.dayNum; j++){//初始化date数组
        date.push(j);
    }
    html_str.push("<table id='calendar'>");
    html_str.push("<caption><span title='上一年份' onmouseover=\"this.style.color='#F90'\" onmouseout=\"this.style.color='#09F'\" onclick=\"JCalendar.update(-12);return false\" style='color:#09F;font-size:16px;margin-right:5px;'>&laquo;</span><span title='上一月份'  onmouseover=\"this.style.color='#F90'\" onmouseout=\"this.style.color='#09F'\" onclick=\"JCalendar.update(-1);return false\" style='margin-right:15px;color:#09F;'>▲</span><span id='calendar_title'>" + this.year + "年" + this.month + "月</span><span title='下一月份' onclick=\"JCalendar.update(1);return false\"  onmouseover=\"this.style.color='#F90'\" onmouseout=\"this.style.color='#09F'\" style='margin-left:15px;color:#09F;'>▼</span><span title='下一年份' onclick=\"JCalendar.update(12);return false\"  onmouseover=\"this.style.color='#F90'\" onmouseout=\"this.style.color='#09F'\" style='font-size:16px;margin-left:5px;color:#09F;'>&raquo;</span></caption>");
    html_str.push("<thead><tr>");
    for(var i = 0; i < 7; i++){//填充日历头
        html_str.push("<td>" + weekDay[i] + "</td>");
    }
    html_str.push("</tr></thead>");
    html_str.push("<tbody>");
    for(var i = 0; i < 6; i++){//填充日期
        html_str.push("<tr>");
        for(var j = 0; j < 7; j++){
            tmp = date[date_index++];
            tmp = tmp ? tmp : "";
            if(JCalendar.cur_date == tmp)
                html_str.push("<td><span id='c_today' style='background-color:#036;color:#FFF;'>" + JCalendar.cur_date + "</span></td>");
            else if(tmp == "")
                html_str.push("<td></td>");
            else
                html_str.push("<td><div onmouseover=\"this.style.backgroundColor='#CCC'\" onmouseout=\"this.style.backgroundColor=''\" onclick='JCalendar.click(this)'>" + tmp + "</div></td>");
        }
        html_str.push("</tr>");
    }
    html_str.push("</tbody></table>");
    return html_str.join("");
}
//静态方法
JCalendar.update = function(_month){
    var date = new Date(JCalendar.cur_year,JCalendar.cur_month - 1 + _month,1);
    var fday = date.getDay();//每月第一天的星期数
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var dayNum = new Date(JCalendar.cur_year,JCalendar.cur_month  + _month,0).getDate();//每月的天数
    var tds = document.getElementById("calendar").getElementsByTagName("td");
    for(var i = 7; i < tds.length; i++)//清空日历内容
    tds[i].innerHTML = "";
    document.getElementById("calendar_title").innerHTML = year + "年" + month + "月";//更新显示年月
    //更新当前年月
    JCalendar.cur_year = year;
    JCalendar.cur_month = month;
    for(var j = 1; j <= dayNum; j++){
        if(j == JCalendar.cur_date)
            tds[6 + fday + j].innerHTML = "<span id='c_today' style='background-color:#036;color:#FFF;'>" + JCalendar.cur_date + "</span>";
        else
            tds[6 + fday + j].innerHTML = "<div onmouseover=\"this.style.backgroundColor='#CCC'\" onmouseout=\"this.style.backgroundColor=''\" onclick='JCalendar.click(this)'>" + j + "</div>";
    }
    JCalendar.onupdate(year,month,JCalendar.cur_date);
}

JCalendar.onupdate = function(year,month,date){//日历更改时执行的函数,可以更改为自己需要函数,控件传递过来的参数为当前日期
    //alert(year + "年" + month + "月" + date + "日");
}

JCalendar.click = function(obj){
    
    var tmp = document.getElementById("c_today");
    tmp.parentNode.innerHTML = "<div onmouseover=\"this.style.backgroundColor='#CCC'\" onmouseout=\"this.style.backgroundColor=''\" onclick='JCalendar.click(this)'>" + tmp.innerHTML + "</div>";
    JCalendar.cur_date = parseInt(obj.innerHTML);
    obj.parentNode.innerHTML = "<span id='c_today' style='background-color:#036;color:#FFF;'>" + obj.innerHTML + "</span>";
    JCalendar.onclick(JCalendar.cur_year,JCalendar.cur_month,JCalendar.cur_date);
    
}

JCalendar.onclick = function(year,month,date){//点击日期时执行的函数,可以更改为自己需要函数,控件传递过来的参数为当前日期
    //alert(year + "年" + month + "月" + date + "日");
//    alert(JCalendar._id);
    
    $("#"+JCalendar._id).val(year+"-"+month+"-"+date);
    $("#calendar_contain_1").hide();
}