首页 web前端 js教程 javascript 日历提醒系统( 兼容所有浏览器 )_时间日期

javascript 日历提醒系统( 兼容所有浏览器 )_时间日期

May 16, 2016 pm 06:54 PM
javascript 日历提醒

功能介绍:
1.正常的日历功能。
2.等等等
3.接收 数组
例如:

复制代码 代码如下:

new Calendar("id").show(
{
"20091120": "今天干了嘛嘛。。。",
"2009320": "今天干了嘛嘛。。。"
}
);

日历提示样式分为3类。
a. 当日
b.当年当月当日提示样式
c.当月当日提示样式
鼠标覆盖在有提示的日期上自动出现提示内容
4.。。。。。
主要分为2种用处。
1.提供一个 div 或其他 element 将该容器的 id 传给 Calendar。方法名为: show()
例: var cr = Calendar("div1");
cr.show( /*data - 该数组为可选项,如果传则有提示功能*/ );
2.提供一个 input[type='text'] 的元素 将该元素的 id 传给 Calendar。方法名为: pop()
例: var cr = Calendar("input2");
cr.pop();
其他的就不多说了。觉得好的话,就支持下。呵呵。
有什么问题或好的想法,请告诉我。谢谢
详细的用法和例子在压缩包里有。
演示地址
http://img.jb51.net/online/calendar/demo-1.html
http://img.jb51.net/online/calendar/demo-2.html
打包下载地址 http://www.jb51.net/codes/12595.html
复制代码 代码如下:

/*
* Calendar
* Language 0: Chinese, 1: English
* 1.Put calendar into the element html use 'show()'
* 2.Pop-up calendar use 'pop()'
*/

var Calendar = function( instanceId, language, startYear, endYear ){
    if( typeof instanceId == "string" ){
        this.Date     = new Date();
        this.Year     = this.Date.getFullYear();
        this.Month     = this.Date.getMonth();
        this.Week    = this.Date.getDay();
        this.Today    = this.Date.getDate();

        this.InstanceId = instanceId;
        this.Language    = language     || 1;
        this.StartYear    = startYear || this.Year - 5;
        this.EndYear    = endYear     || this.Year + 1;

        // If instance is input[type='text'] object
        this.popContainer_id = 'popCalendarContainer';

        // Message store
        this.msgStore = [];

        this.caleContainer_id = 'calendarContainer';
        this.caleTop = {
            today_view_id:        'calendarTodayView',
            week_view_id:        'calendarWeekView',
            lq_year_id:            'linkQuickYear',
            lq_month_id:        'linkQuickMonth',
            sq_year_id:            'selectQuickYear',
            sq_month_id:        'selectQuickMonth',
            close_id:            'calendarClose',
            prev_month_id:        'toPrevMonth',
            back_today_id:        'backToday',
            next_month_id:        'toNextMonth'
        }
        this.daysContainer_id = 'calendarDaysContainer';
        this.msgContainer_id = 'calendarTipsContainer';

        this.curDayClass =         'calendarCurrentDay';
        this.tipDayClass =        'calendarTipDay';
        this.oldTipDayClass =    'calendarOldTipDay';
    }
};
/* Calendar language */
Calendar.lang = {
weeks:     [
                ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
                ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
            ],
weeksMenu:[
                 ["日","一","二","三","四","五","六"],
             ["SUN","MON","TUR","WED","THU","FRI","SAT"]
    ]
};
/* Create calendar element */
Calendar.prototype._getViewElement = function(){
    // Create page html element
    var caleElem = "";
        // Create Start
        caleElem+= '
';

        //
        caleElem+= '
';

        // Top day view
        caleElem+= '';

        // Link or select control
        caleElem+= '';

        // Quick control
        caleElem+= '';

        caleElem+= '
';
        caleElem+= '
';
        caleElem+= '';
        caleElem+= '';
        caleElem+= '';
        caleElem+= '';
        caleElem+= '';
        caleElem+= '';
        caleElem+= '
';
        caleElem+= '';
        caleElem+= '';
        caleElem+= '
.';
        caleElem+= '';
        caleElem+= '';
        caleElem+= '
';
        caleElem+= '
';
        caleElem+= '
';
        caleElem+= 'x';
        caleElem+= '
';

        caleElem+= '
';
        caleElem+= '«';
        caleElem+= ' ';
        caleElem+= '»';
        caleElem+= '
';
        caleElem+= '
cellpadding="0" cellspacing="0">
';
        //


        //
        caleElem+= '
';
        // Week menu
        caleElem+= '
';
        for(var i = 0; i         caleElem+= ''+Calendar.lang["weeksMenu"][this.Language][i]+'';
        }
        caleElem+= '
';

        // Days view
        caleElem+= '';
        for(var tr = 0; tr         caleElem+= '';
        for(var td = 0; td         caleElem+= '';
        }
        caleElem+= '';
        }
        caleElem+= '
';

        caleElem+= '
';
        //
View>

        caleElem+= '
';

        //
        caleElem+= '
';
        //
msg>

        // Create End
    return caleElem;
};
/* Get Month Data */
Calendar.prototype._getMonthViewArray = function( year, month ){
    var monthArray = [];
    // From the beginning day of the week
    var beginDayOfWeek = new Date( year, month, 1).getDay();

    // This month total days
    var daysOfMonth = new Date( year, month + 1, 0).getDate();

    // 42: 7*6 matrix
    for( var i = 0; i      monthArray[i] = " ";

    for( var j = 0; j         monthArray[j + beginDayOfWeek] = j + 1 ;

    return monthArray;
};
/* Search the index of option in the select */
Calendar.prototype._getOptionIndex = function( selectObject, value ){
    for( var j = 0; j         if( value == selectObject.options[j].value )
            return j;
    }
};
/* Bind year data into 'Year select' */
Calendar.prototype._bindYearIntoSelect = function(){
    var oYear = this.find( this.caleTop.sq_year_id );
    var oYearLen = 0;
    for( var i = this.StartYear; i         oYear.options[oYearLen] = new Option( i , i );
};
/* Bind Month data into 'Month select' */
Calendar.prototype._bindMonthIntoSelect = function(){
    var oMonth = this.find( this.caleTop.sq_month_id );
    var oMonthLen = 0;
    for( var i = 0; i         oMonth.options[oMonthLen] = new Option( i + 1 , i + 1 );
};
/* Bind data */
Calendar.prototype._bindAllData = function( curYear, curMonth ){
    var cr = this;
    // Bind default Data into 'select:Year'
    this._bindYearIntoSelect();

    // Bind default Data into 'select:Month'
    this._bindMonthIntoSelect();

    // Change the 'select:Year' and 'select:Month' value
    this.changeSelectValue( curYear, curMonth );

    // Bind default data into 'current day view and current week view'
    this.find( this.caleTop.week_view_id ).innerHTML = Calendar.lang['weeks'][this.Language][this.Week];
    this.find( this.caleTop.today_view_id ).innerHTML = this.Today;

    // Get days and bind into 'CalendarMain'
    // Add current day class and mouse event
    var daysOfMonthArray = this._getMonthViewArray( curYear, curMonth );
    var spans = this.find( this.daysContainer_id, "span" );
    var curYMD = this.Year + "" + ( this.Month + 1 ) + "" + this.Today;
    var selectYear = this.find( this.caleTop.sq_year_id ).value;
    var selectMonth = this.find( this.caleTop.sq_month_id ).value;
    for( var i = 0; i         spans[i].innerHTML = daysOfMonthArray[i];
        var selectYMD = selectYear + "" + selectMonth + "" + spans[i].innerHTML;
        if( curYMD == selectYMD )
            spans[i].className = this.curDayClass;
        else
            spans[i].className = "";
    }
    // If not some days has pop message
    if( this.msgStore != "" )
        this._initPopMsg( this.msgStore );
}
/* Bind event */
Calendar.prototype._bindAllEvent = function(){
    var cr = this;
    // 'toPrevMonth, toNextMonth, backToday, today view' event
    this.find( this.caleTop.prev_month_id ).onclick = function(){ cr.goPrevOrNextMonth(this); };
    this.find( this.caleTop.next_month_id ).onclick = function(){ cr.goPrevOrNextMonth(this); };
    this.find( this.caleTop.back_today_id ).onclick    = function(){ cr.backToday(); };
    this.find( this.caleTop.today_view_id ).onclick = function(){ cr.backToday(); };

    // 'year and month select' onchange event
    this.find( this.caleTop.sq_year_id ).onchange = function(){ cr.updateSelect(); };
    this.find( this.caleTop.sq_month_id ).onchange    = function(){ cr.updateSelect(); };

    // Quick link event
    this.find( this.caleTop.lq_year_id ).onclick = function(){
        cr.showHide( cr.caleTop.lq_year_id, "none" );
        cr.showHide( cr.caleTop.sq_year_id, "block" );
    };
    this.find( this.caleTop.lq_month_id ).onclick = function(){
        cr.showHide( cr.caleTop.lq_month_id, "none" );
        cr.showHide( cr.caleTop.sq_month_id, "block" );
    };

    // Remove the link dotted line
    var oLink = this.find( this.caleContainer_id, "a" )
    for( var i = 0; i         oLink[i].onfocus = function(){ this.blur(); }
    }
}
/* Bind calendar for calendar view */
Calendar.prototype._initCalendar = function(){
    this._bindAllEvent();
    this._bindAllData( this.Year, this.Month );
};
/* Change the quick select value */
Calendar.prototype.changeSelectValue = function( year, month ){
    var ymArray = [], selectArray = [], linkArray = [];
    // Store the 'year' and 'month' to Array
    ymArray[0] = year; ymArray[1] = month + 1;

    // Store the 'selectYear_id' and 'selectMonth_id' to Array
    selectArray[0] = this.caleTop.sq_year_id; selectArray[1] = this.caleTop.sq_month_id;

    linkArray[0] = this.caleTop.lq_year_id; linkArray[1] = this.caleTop.lq_month_id;

    for( var i = 0; i         var selectObject = this.find( selectArray[i] );
        // Get the return index
        var index = this._getOptionIndex( selectObject, ymArray[i] );
        // Reset the 'year', 'month' select and link value
        selectObject.options[index].selected = "selected";

        this.find( linkArray[i] ).innerHTML = selectObject.value;
    }

    this.resetLinkSelect();
};
/* Search next or previons month */
Calendar.prototype.goPrevOrNextMonth = function( obj ){
    var curMonthSelect = this.find( this.caleTop.sq_month_id );
    var curMonth = parseInt( curMonthSelect.value );
    var curYear = this.find( this.caleTop.sq_year_id ).value;
    // If 'next' get current month select + 1
    // If 'prev' get current month select - 1
    if( obj.id == this.caleTop.next_month_id )
        curMonthSelect.value = curMonth + 1;
    else
        curMonthSelect.value = curMonth - 1;

    var getNowMonth = curMonthSelect.value - 1;
    if( getNowMonth == -1 && curMonth == 1)     getNowMonth = 0;
    if( getNowMonth == -1 && curMonth == 12 )     getNowMonth = 11;

    this._bindAllData( curYear, getNowMonth );
};
/* If 'select:Year' and 'select:Month' change value update data */
Calendar.prototype.updateSelect = function(){
    var yearSelectValue     = this.find( this.caleTop.sq_year_id ).value;
    var monthSelectValue = this.find( this.caleTop.sq_month_id ).value;
    // Re-bind Panel Data
    this._bindAllData( yearSelectValue, monthSelectValue - 1 );

};
/* Back to taday: re-load '_bindAllData()' */
Calendar.prototype.backToday = function(){
    this._bindAllData( this.Year, this.Month );
};
/* Find the instance object or children of instance object by Id */
Calendar.prototype.find = function( elemId, childTag ){
    if( !childTag )
        // Return: object
        return document.getElementById( elemId );
    else
        // Return: object array
        return this.find( elemId ).getElementsByTagName( childTag );
};
/* Set element css */
Calendar.prototype.css = function( oId, selector ){
    var o = this.find( oId );
    selector['left']?o.style.left = selector['left']:"";
    selector['top']?o.style.top = selector['top']:"";
    selector['position']? o.style.position = selector['position']:"";
}
/* Check calendar show or hidden */
Calendar.prototype.showHide = function( objectId, dis ){
    return this.find( objectId ).style.display = dis;
};
/* Init the top quick menu link and select */
Calendar.prototype.resetLinkSelect = function(){
    this.showHide( this.caleTop.sq_year_id, "none" );
    this.showHide( this.caleTop.sq_month_id, "none" );
    this.showHide( this.caleTop.lq_year_id, "block" );
    this.showHide( this.caleTop.lq_month_id, "block" );
};
/* Put this calendar into the html of instance */
Calendar.prototype.show = function( msgData ){
    var obj = this.find( this.InstanceId );
    if( obj ){
        obj.innerHTML = this._getViewElement();
        // Init calendar event and data
        this._initCalendar();

        // This function don't have 'close'
        this.showHide( this.caleTop.close_id, "none" );
        if( typeof msgData == 'object'){
            this.msgStore = msgData;
            this._initPopMsg( this.msgStore );
        }
    }
};
/* Init pop message */
Calendar.prototype._initPopMsg = function(){
    var cr = this;
    var selectYear = this.find( this.caleTop.sq_year_id ).value;
    var selectMonth = this.find( this.caleTop.sq_month_id ).value;
    var daysOfMonthArray = this._getMonthViewArray( selectYear, selectMonth );
    var spans = this.find( this.daysContainer_id, "span" );
    for( var key in this.msgStore ){
        var keyMD = key.substring( 4 );
        var keyY = key.substring( 0, 4 );
        for( var i = 0; i             var getMD = selectMonth + "" + spans[i].innerHTML;
            if( getMD == keyMD ){
                if( selectYear == keyY )
                    spans[i].className = this.tipDayClass +" "+ keyY;
                else
                    spans[i].className = this.oldTipDayClass +" "+ keyY;    
                spans[i].onmouseover = function(){
                    var hoverDate = this.className.split(" ")[1] + "" + selectMonth + "" + this.innerHTML;
                    var y = this.className.split(" ")[1],
                        m = selectMonth,
                        d = this.innerHTML;
                    cr.find( cr.msgContainer_id ).innerHTML = cr._getMsgHtml( y, m, d );
                    cr.showHide( cr.msgContainer_id, "block" );
                }
            }
        }
    }
    cr.find( cr.caleContainer_id ).onmouseout = function(){
        cr.showHide( cr.msgContainer_id, "none" );
    }
};
/* Get message */
Calendar.prototype._getMsgHtml =function( y, m, d ){
    var date = y + m + d;
    var showDate = y + "-" + m + "-" + d;
    var msgHtml = '
'+showDate+':
'+ this.msgStore[date] +'
';
    return msgHtml;
}
/* Pop-up the calendar */
Calendar.prototype.pop = function(){
    var cr = this;
    var obj    = this.find( this.InstanceId );
    if( obj ){
        // Instance object click then pop-up the calendar
        obj.onclick = function( e ){
            var e = window.event || e;
            var x = e.x || e.pageX,
                y = e.y || e.pageY;
            if( !cr.find( cr.popContainer_id ) ){
                // Create the pop-up div
                var oDiv = document.createElement("div");
                oDiv.id = cr.popContainer_id;
                document.body.appendChild( oDiv );
            }else{
                cr.showHide( cr.popContainer_id, "block" );
            }
            cr.find( cr.popContainer_id ).innerHTML = cr._getViewElement();

            // Init calendar event and data
            cr._initCalendar();

            // Set days click event
            cr.popDaysClickEvent( obj );

            // Set position
            cr.css( cr.popContainer_id, {position: "absolute", left: x + "px", top: y + "px"});

            // Close panel event
            cr.find( cr.caleTop.close_id ).onclick = function(){ cr.showHide( cr.popContainer_id, "none" ); };
        };
    }
};
/* Click the pop calendar days event [For INPUT] */
Calendar.prototype.popDaysClickEvent = function( obj ){
    var cr = this;
    var spans = cr.find( cr.daysContainer_id, "span" );
    for( var i = 0; i         spans[i].onclick = function(){
            if( this.innerHTML != " " ){
                var getYear     = cr.find( cr.caleTop.sq_year_id ).value;
                var getMonth = cr.find( cr.caleTop.sq_month_id ).value;
                obj.value = getYear +"-"+ getMonth +"-" + this.innerHTML;
                cr.showHide( cr.popContainer_id, "none" );
            }
        }
};
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前 By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

如何使用WebSocket和JavaScript实现在线语音识别系统 如何使用WebSocket和JavaScript实现在线语音识别系统 Dec 17, 2023 pm 02:54 PM

如何使用WebSocket和JavaScript实现在线语音识别系统引言:随着科技的不断发展,语音识别技术已经成为了人工智能领域的重要组成部分。而基于WebSocket和JavaScript实现的在线语音识别系统,具备了低延迟、实时性和跨平台的特点,成为了一种被广泛应用的解决方案。本文将介绍如何使用WebSocket和JavaScript来实现在线语音识别系

WebSocket与JavaScript:实现实时监控系统的关键技术 WebSocket与JavaScript:实现实时监控系统的关键技术 Dec 17, 2023 pm 05:30 PM

WebSocket与JavaScript:实现实时监控系统的关键技术引言:随着互联网技术的快速发展,实时监控系统在各个领域中得到了广泛的应用。而实现实时监控的关键技术之一就是WebSocket与JavaScript的结合使用。本文将介绍WebSocket与JavaScript在实时监控系统中的应用,并给出代码示例,详细解释其实现原理。一、WebSocket技

如何使用WebSocket和JavaScript实现在线预约系统 如何使用WebSocket和JavaScript实现在线预约系统 Dec 17, 2023 am 09:39 AM

如何使用WebSocket和JavaScript实现在线预约系统在当今数字化的时代,越来越多的业务和服务都需要提供在线预约功能。而实现一个高效、实时的在线预约系统是至关重要的。本文将介绍如何使用WebSocket和JavaScript来实现一个在线预约系统,并提供具体的代码示例。一、什么是WebSocketWebSocket是一种在单个TCP连接上进行全双工

如何利用JavaScript和WebSocket实现实时在线点餐系统 如何利用JavaScript和WebSocket实现实时在线点餐系统 Dec 17, 2023 pm 12:09 PM

如何利用JavaScript和WebSocket实现实时在线点餐系统介绍:随着互联网的普及和技术的进步,越来越多的餐厅开始提供在线点餐服务。为了实现实时在线点餐系统,我们可以利用JavaScript和WebSocket技术。WebSocket是一种基于TCP协议的全双工通信协议,可以实现客户端与服务器的实时双向通信。在实时在线点餐系统中,当用户选择菜品并下单

简易JavaScript教程:获取HTTP状态码的方法 简易JavaScript教程:获取HTTP状态码的方法 Jan 05, 2024 pm 06:08 PM

JavaScript教程:如何获取HTTP状态码,需要具体代码示例前言:在Web开发中,经常会涉及到与服务器进行数据交互的场景。在与服务器进行通信时,我们经常需要获取返回的HTTP状态码来判断操作是否成功,根据不同的状态码来进行相应的处理。本篇文章将教你如何使用JavaScript获取HTTP状态码,并提供一些实用的代码示例。使用XMLHttpRequest

JavaScript和WebSocket:打造高效的实时天气预报系统 JavaScript和WebSocket:打造高效的实时天气预报系统 Dec 17, 2023 pm 05:13 PM

JavaScript和WebSocket:打造高效的实时天气预报系统引言:如今,天气预报的准确性对于日常生活以及决策制定具有重要意义。随着技术的发展,我们可以通过实时获取天气数据来提供更准确可靠的天气预报。在本文中,我们将学习如何使用JavaScript和WebSocket技术,来构建一个高效的实时天气预报系统。本文将通过具体的代码示例来展示实现的过程。We

如何在JavaScript中获取HTTP状态码的简单方法 如何在JavaScript中获取HTTP状态码的简单方法 Jan 05, 2024 pm 01:37 PM

JavaScript中的HTTP状态码获取方法简介:在进行前端开发中,我们常常需要处理与后端接口的交互,而HTTP状态码就是其中非常重要的一部分。了解和获取HTTP状态码有助于我们更好地处理接口返回的数据。本文将介绍使用JavaScript获取HTTP状态码的方法,并提供具体代码示例。一、什么是HTTP状态码HTTP状态码是指当浏览器向服务器发起请求时,服务

javascript中如何使用insertBefore javascript中如何使用insertBefore Nov 24, 2023 am 11:56 AM

用法:在JavaScript中,insertBefore()方法用于在DOM树中插入一个新的节点。这个方法需要两个参数:要插入的新节点和参考节点(即新节点将要被插入的位置的节点)。

See all articles