jquery-written calendars (including the style and function of calendars) _jquery

Source: Internet
Author: User
Tags border color getdate
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<script src= ". /js/connotation.js "type=" Text/javascript "></script>
<script type= "Text/javascript" >
var c = new Calendar ("C");
document.write (c);
</script>
<body>
<div>
Normal call: <input type= "text" name= "txt2" onclick= "c.showmoreday = true; C.show (this); "/><br/>
<div style= "height:262px" >
</div>
Button call: <input type= "text" name= "Btntxt" id= "Btntxt"/><input "button" name= "*"
Id= "button" type= "button" onclick= "C.showmoreday = true; C.show (Getobjbyid (' btntxt '), ' 1982-1-1 ', this) '/>
<br/>
<input type= "text" name= "Btntxt3" id= "Btntxt3"/><input "name=" button3 "*"
Id= "Button3" type= "button" onclick= "C.showmoreday = true; C.show (This, Getobjbyid (' Btntxt3 ')) "/>
</div>
</body>

Required jquery File
Copy Code code as follows:

function Calendar (objname)
{
This.style = {
BorderColor: "#909eff",//Border color
HeaderBackColor: "#909EFF",//table header background color
Headerfontcolor: "#ffffff",//Header font Color
Bodybarbackcolor: "#f4f4f4",//Calendar title background color
Bodybarfontcolor: "#000000",//Calendar title font Color
Bodybackcolor: "#ffffff",//Calendar background color
Bodyfontcolor: "#000000",//Calendar font Color
Bodyholidayfontcolor: "#ff0000",//Holiday font Color
Watermarkcolor: "#d4d4d4",//Background watermark Color
Moredaycolor: "#cccccc"
};
This.showmoreday = false; Show dates for last month and next month
This. OBJ = objname;
This.date = null;
This.mouseoffset = null;
This.dateinput = null;
This.timer = null;
};
Calendar.prototype.toString = function ()
{
var str = This.getstyle ();
str = ' <div author= ' Alin "class=" Calendar "style=" Display:none; "onselectstart=" return false "oncontextmenu=" return false "id=" Calendar ">\n";
STR + + ' <div author= ' Alin "class=" Cdrwatermark "id=" Cdrwatermark "></div><div id=" CdrBody "style=" position:absolute;left:0px;top:0px;z-index:2;width:140px; " > ';
str = This.getheader ();
str = This.getbody ();
STR + + ' </div><div author= ' Alin "id=" Cdrmenu "style=" Position:absolute;left:0px;top:0px;z-index:3;display: none; "onmouseover=" ' + this. OBJ + '. ShowMenu (null); "onmouseout=" ' + this. OBJ + '. Hidemenu (); " ></div></div> ';
return str;
};
Calendar.prototype.getStyle = function ()
{
var str = ' <style type= ' text/css ' >\n ';
str = '. calendar{position:absolute;width:140px!important;width:142px;height:184px!important;height:174px; Background-color: ' +this.style.bodybackcolor+ '; border:1px solid ' + This.style.borderColor + '; left:0px;top:0px; z-index:9999;} \ n ';
str = '. Cdrheader{background-color: ' + This.style.headerBackColor + '; Width:140px;height:22px;font-size:12px;color: ' +this.style.headerfontcolor+ ';} \ n ';
str = '. Cdrwatermark{position:absolute;left:0px;top:55px;width:140px;font-family:arial Black;font-size:50px; Color: ' +this.style.watermarkcolor+ '; z-index:1;text-align:center;} \ n ';
str = '. Cdrbodybar{background-color: ' + This.style.bodyBarBackColor + '; Font-size:12px;color: ' + This.style.bodyBarFontColor + '; width:140px;height:20px;} \ n ';
str = '. Cdrbody{width:140px;height:122px!important height:110px;font-size:12px;cursor:pointer;color: ' + This.style.bodyFontColor + ';} \ n ';
str = '. dayover{height:16px;padding:0px;border:1px solid Black;background-color: #f4f4f4;} \ n ';
str = '. dayout{padding:1px;border:none;height:16px;} \ n ';
str = '. Menuover{background-color: ' +this.style.headerbackcolor+ '; color: ' +this.style.headerfontcolor+ '; font-size : 12px;} \ n ';
str = '. headerover{border:1px solid black;background-color: #f4f4f4; color:black;cursor:default;} \ n ';
str = '. cdrmenu{font-size:12px;border:1px solid #000000; Background-color: #ffffff; cursor:default;width:100%}\n ';
STR + + ' html>body #Calendar {width:142px;174px;} ';
str = ' </style>\n ';
return str;
};
Calendar.prototype.getHeader = function ()
{
var str = ' <table author= "Alin" class= "Cdrheader" cellspacing= "2" cellpadding= "0" ><tr author= "Alin" align= " Center ">\n";
str = ' <td author= ' Alin ' onmouseover= ' this.classname=\ ' headerover\ ' ' onmouseout= ' this.classname=\ ' ' id= ' Previousyear "Title=" the previous year "style=" cursor:pointer;width:10px; "onclick=" ' +this. Obj+ '. Onchangeyear (FALSE); ><<</td>\n ';
str = ' <td author= ' Alin ' onmouseover= ' this.classname=\ ' headerover\ ' ' onmouseout= ' this.classname=\ ' ' id= ' Previousmonth "title=" on January "style=" cursor:pointer;width:10px; "onclick=" ' +this. Obj+ '. Onchangemonth (FALSE); ><</td>\n ';
STR + + "&LT;TD author=" Alin "onmouseover=" this.classname=\ ' headerover\ ' "id=" CurrentYear "style="; "onclick = "' + this. OBJ + '. ShowMenu (true); ' onmouseout= ' + this. OBJ + '. Hidemenu (); this.classname=\ '; >0</td>\n ';
STR + + "&LT;TD author=" Alin "onmouseover=" this.classname=\ ' headerover\ ' "id=" Currentmonth "onclick=" ' + this. OBJ + '. ShowMenu (false); "onmouseout=" ' + this. OBJ + '. Hidemenu (); this.classname=\ '; >0</td>\n ';
str = ' <td author= ' Alin ' onmouseover= ' this.classname=\ ' headerover\ ' ' onmouseout= ' this.classname=\ ' ' id= ' Nextmonth "title=" Next January "style=" cursor:pointer;width:10px; "onclick=" ' +this. Obj+ '. Onchangemonth (True); >></td>\n ';
str = ' <td author= ' Alin ' onmouseover= ' this.classname=\ ' headerover\ ' ' onmouseout= ' this.classname=\ ' ' id= ' Nextyear "Title=" the next year "style=" cursor:pointer;width:10px; "onclick=" "+this". Obj+ '. Onchangeyear (True); >>></td></tr>\n ';
str = ' </table>\n ';
return str;
};
Calendar.prototype.getBody = function ()
{
var n = 0;
var str = This.getbodybar ();
str = ' <table author= "Alin" class= "Cdrbody" cellspacing= "2" cellpadding= "0" >\n ";
for (i = 0; i < 6; i++)
{
str = ' <tr author= ' Alin ' align= ' center ' > ';
for (j = 0; J < 7; J + +)
{
STR + + ' <td author= ' Alin ' class= ' dayout ' id= ' cdrday ' + (n++) + ' width= ' 13% ' ></td>\n ';
}
str = ' </tr> ';
}
str = ' </table>\n ';
str = ' <table author= "Alin" class= "Cdrbodybar" cellspacing= "2" cellpadding= "0" ><tr align= "center" Author= " Alin "><td author=" Alin "style=" Cursor:pointer "onclick=" "+this". Obj+ '. Gettoday (); > Today: ' +new date (). toformatstring ("yyyy mm month DD Day") + ' </td></tr></table>\n ';
return str;
};
Calendar.prototype.getBodyBar = function ()
{
var str = ' <table author= ' Alin_bar "id=" Cdrbodybar "class=" Cdrbodybar "style=" cursor:move; "cellspacing=" 2 " cellpadding= "0" ><tr author= "Alin_bar" align= "center" >\n ";
var day = new Array (' th ', ' One ', ' two ', ' three ', ' four ', ' five ', ' six ');
for (i = 0; i < 7; i++)
{
STR + + ' <td author= ' alin_bar ' > ' + day[i] + ' </td>\n ';
}
str = ' </tr></table> ';
return str;
}
Calendar.prototype.getYearMenu = function (year)
{
var str = ' <table author= "Alin" cellspacing= "0" class= "cdrmenu" cellpadding= "0" >\n ";
for (i = 0; i < i++)
{
var _year = year + i;
var _date = new Date (_year,this.date.getmonth (), this.date.getDate ());
str = ' <tr author= "Alin" align= "center" ><td author= "Alin" width= "13%" height= "16";
if (This.date.getFullYear ()!= _year)
{
str = ' onmouseover= ' this.classname=\ ' menuover\ ' onmouseout= ' this.classname=\ ' "';
}
Else
{
STR + + ' class= ' menuover ';
}
STR + + ' onclick= ' + this. OBJ + '. Binddate (\ ' + _date.toformatstring ("-") + ' + ') ' > ' + _year + ' year </td>\n ';
str = ' </tr> ';
}
STR + + "<tr author=" Alin "align=" center "><td author=" Alin "><table author=" Alin "style=" FONT-SIZE:12PX; width:100%; "cellspacing=" 0 "cellpadding=" 0 ">\n";
str = ' <tr author= "Alin" align= "center" ><td author= "Alin" onmouseover= "this.classname=\ ' Menuover\ '" onmouseout= "This.classname=\ '" "onclick=" ' +this. Obj+ '. Getyearmenu (' + (year-10) + ') ' ><<</td>\n ';
str = ' <td author= ' Alin "onmouseover=" this.classname=\ ' menuover\ ' "onmouseout=" This.classname=\ ' "" onclick= "' + This. Obj+ '. Getyearmenu (' + (year +) + ') ' >>></td><tr>\n ';
str = ' </table></td></tr>\n ';
str = ' </table> ';
var _menu = Getobjbyid ("Cdrmenu");
_menu.innerhtml = str;
};
Calendar.prototype.getMonthMenu = function ()
{
var str = ' <table author= "Alin" cellspacing= "0" class= "cdrmenu" cellpadding= "0" >\n ";
for (i = 1; I <= i++)
{
var _date = new Date (This.date.getFullYear (), i-1,this.date.getdate ());
str = ' </tr><tr author= "Alin" align= "center" ><td author= "Alin" height= "16";
if (This.date.getMonth () + 1!= i)
{
str = ' onmouseover= ' this.classname=\ ' menuover\ ' onmouseout= ' this.classname=\ ' "';
}
Else
{
STR + + ' class= ' menuover ';
}
STR + + ' onclick= ' + this. OBJ + '. Binddate (\ ' + _date.toformatstring ("-") + ') ' > ' +i+ ' month </td></tr>\n ';
}
str = ' </table> ';
var _menu = Getobjbyid ("Cdrmenu");
_menu.innerhtml = str;
};
Calendar.prototype.show = function ()
{
if (Arguments.length > 3 | | | arguments.length = 0)
{
Alert ("Sorry!") Incoming parameter is wrong! " );
Return
}
var _date = null;
var _evobj = null;
var _initvalue = null
for (i = 0; i < arguments.length; i++)
{
if (typeof (Arguments[i]) = = "Object" && Arguments[i].type = = "Text")
{_date = arguments[i];}
else if (typeof (Arguments[i]) = = "Object")
{_evobj = arguments[i];}
else if (typeof (Arguments[i]) = = "string")
{_initvalue = arguments[i];}
}
_evobj = _evobj | | _date;
Inputobj = _date;
Targetobj = _evobj
if (!_date) {alert ("Incoming parameter Error!");
This.dateinput = _date;
_date = _date.value;
if (_date = = "" && _initvalue) _date = _initvalue;
This.binddate (_date);
var _target = getPosition (_evobj);
var _obj = Getobjbyid ("Calendar");
_obj.style.display = "";
_obj.style.left = _target.x + ' px ';
if ((Document.body.clientHeight-(_target.y + _evobj.clientheight)) >= _obj.clientheight)
{
_obj.style.top = (_target.y + _evobj.clientheight) + ' px ';
}
Else
{
_obj.style.top = (_target.y-_obj.clientheight) + ' px ';
}
};
Calendar.prototype.hide = function ()
{
var obj = Getobjbyid ("Calendar");
Obj.style.display = "None";
};
Calendar.prototype.bindDate = function (date)
{
var _monthdays = new Array (31,30,31,30,31,30,31,31,30,31,30,31);
var _arr = date.split ('-');
var _date = new Date (_arr[0],_arr[1]-1,_arr[2]);
if (isNaN (_date)) _date = new Date ();
This.date = _date;
This.bindheader ();
var _year = _date.getfullyear ();
var _month = _date.getmonth ();
var _day = 1;
var _startday = new Date (_year,_month,1). Getday ();
var _previyear = _month = = 0? _year-1: _year;
var _previmonth = _month = = 0? One: _month-1;
var _previday = _monthdays[_previmonth];
if (_previmonth = 1) _previday = (_previyear%4==0) && (_previyear0!=0) | | (_previyear@0==0))? 29:28;
_previday-= _startday-1;
var _nextday = 1;
_MONTHDAYS[1] = ((_year%4==0) && (_year0!=0) | | (_year@0==0))? 29:28;
for (i = 0; i < i++)
{
var _dayelement = Getobjbyid ("cdrday" + i);
_dayelement.onmouseover = Function (this. OBJ + ". OnMouseOver (This)");
_dayelement.onmouseout = Function (this. OBJ + ". onmouseout (This)");
_dayelement.onclick = Function (this. OBJ + ". OnClick (This)");
This.onmouseout (_dayelement);
_dayelement.style.color = "";
if (I < _startday)
{
Get a date on one months
if (this.showmoreday)
{
var _previdate = new Date (_year,_month-1,_previday);
_dayelement.innerhtml = _previday;
_dayelement.title = _previdate.toformatstring ("YYYY year mm month DD Day");
_dayelement.value = _previdate.toformatstring ("-");
_dayelement.style.color = This.style.moreDayColor;
_previday++;
}else
{
_dayelement.innerhtml = "";
_dayelement.title = "";
}
}
else if (_day > _monthdays[_month])
{
Get the date of next month
if (this.showmoreday)
{
var _nextdate = new Date (_year,_month + 1,_nextday);
_dayelement.innerhtml = _nextday;
_dayelement.title = _nextdate.toformatstring ("YYYY year mm month DD Day");
_dayelement.value = _nextdate.toformatstring ("-");
_dayelement.style.color = This.style.moreDayColor;
_nextday++;
}else
{
_dayelement.innerhtml = "";
_dayelement.title = "";
}
}
else if (I >= new Date (_year,_month,1). Getday () && _day <= _monthdays[_month])
{
Get this month's date
_dayelement.innerhtml = _day;
if (_day = = _date.getdate ())
{
This.onmouseover (_dayelement);
_dayelement.onmouseover = Function ("");
_dayelement.onmouseout = Function ("");
}
if (This.isholiday (_year,_month,_day))
{
_dayelement.style.color = This.style.bodyHolidayFontColor;
}
var _curdate = new Date (_year, _month, _day);
_dayelement.title = _curdate.toformatstring ("YYYY year mm month DD Day");
_dayelement.value = _curdate.toformatstring ("-");
_day++;
}
Else
{
_dayelement.innerhtml = "";
_dayelement.title = "";
}
}
var _menu = Getobjbyid ("Cdrmenu");
_menu.style.display = "None";
};
Calendar.prototype.bindHeader = function ()
{
var _curyear = Getobjbyid ("CurrentYear");
var _curmonth = Getobjbyid ("Currentmonth");
var _watermark = Getobjbyid ("Cdrwatermark");
_curyear.innerhtml = this.date.toFormatString ("yyyy year");
_curmonth.innerhtml = this.date.toFormatString ("mm month");
_watermark.innerhtml = This.date.getFullYear ();
};
Calendar.prototype.getToday = function ()
{
var _date = new Date ();
This.binddate (_date.toformatstring ("-"));
};
Calendar.prototype.isHoliday = function (year,month,date)
{
var _date = new Date (year,month,date);
Return (_date.getday () = = 6 | | _date.getday () = 0);
};
Calendar.prototype.onMouseOver = function (obj)
{
Obj.classname = "Dayover";
};
Calendar.prototype.onMouseOut = function (obj)
{
Obj.classname = "Dayout";
};
Calendar.prototype.onClick = function (obj)
{
if (obj.innerhtml!= "") This.dateInput.value = Obj.value;
This.hide ();
};
Calendar.prototype.onChangeYear = function (Isnext)
{
var _year = This.date.getFullYear ();
var _month = this.date.getMonth () + 1;
var _date = This.date.getDate ();
if (_year > 999 && _year <10000)
{
if (isnext) {_year++;} else{_year--;}
}
Else
{
Alert ("Year out of range (1000-9999)!");
}
This.binddate (_year + '-' + _month + '-' + _date);
};
Calendar.prototype.onChangeMonth = function (Isnext)
{
var _year = This.date.getFullYear ();
var _month = this.date.getMonth () + 1;
var _date = This.date.getDate ();
if (isnext) {_month + +;} else {_month--;}
if (_year > 999 && _year <10000)
{
if (_month < 1) {_month = _year--;}
if (_month >) {_month = 1; _year++;}
}
Else
{
Alert ("Year out of range (1000-9999)!");
}
This.binddate (_year + '-' + _month + '-' + _date);
};
Calendar.prototype.showMenu = function (isyear)
{
var _menu = Getobjbyid ("Cdrmenu");
if (isyear!= null)
{
var _obj = (isyear)? Getobjbyid ("CurrentYear"): Getobjbyid ("Currentmonth");
if (isyear)
{
This.getyearmenu (This.date.getFullYear ()-5);
}
Else
{
This.getmonthmenu ();
}
_menu.style.top = (_obj.offsettop + _obj.offsetheight) + ' px ';
_menu.style.left = _obj.offsetleft + ' px ';
_menu.style.width = _obj.offsetwidth + ' px ';
}
if (This.timer!= null) cleartimeout (This.timer);
_menu.style.display= "";
}
Calendar.prototype.hideMenu = function ()
{
var _obj = Getobjbyid ("Cdrmenu");
This.timer = Window.settimeout (function () {_obj.style.display= ' none ';},500);
}
Number.prototype.NaN0 = function ()
{
Return isNaN (this)? 0:this;
}
Date.prototype.toFormatString = function (FS)
{
if (fs.length = 1)
{
return this.getfullyear () + FS + (This.getmonth () + 1) + FS + this.getdate ();
}
FS = Fs.replace ("yyyy", this.getfullyear ());
FS = Fs.replace ("MM", (This.getmonth () + 1));
FS = Fs.replace ("dd", This.getdate ());
return FS;
}
var inputobj = null;
var targetobj = null;
var dragobj = null;
var mouseoffset = null;
function Getobjbyid (obj)
{
if (document.getelementbyidx_x)
{
return document.getelementbyidx_x (obj);
}
Else
{
Alert ("Browser does not support!");
}
}
function mousecoords (EV)
{
if (Ev.pagex | | ev.pagey) {
return {x:ev.pagex, y:ev.pagey};
}
return {
X:ev.clientx + Document.body.scrollleft-document.body.clientleft,
Y:ev.clienty + document.body.scrolltop-document.body.clienttop
};
}
function GetPosition (e)
{
var left = 0;
var top = 0;
while (e.offsetparent) {
Left + = E.offsetleft + (E.currentstyle? parseint (E.currentstyle.borderleftwidth)). NaN0 (): 0);
Top + = E.offsettop + (E.currentstyle? parseint (E.currentstyle.bordertopwidth)). NaN0 (): 0);
e = e.offsetparent;
}
Left + = E.offsetleft + (E.currentstyle? parseint (E.currentstyle.borderleftwidth)). NaN0 (): 0);
Top + = E.offsettop + (E.currentstyle? parseint (E.currentstyle.bordertopwidth)). NaN0 (): 0);
return {x:left, y:top};
}
function Getmouseoffset (target, Ev)
{
EV = EV | | window.event;
var docpos = getPosition (target);
var mousepos = mousecoords (EV);
return {x:mousepos.x-docpos.x, y:mousepos.y-docpos.y};
}
function Closecalendar (evt) {
EVT = EVT | | window.event;
var _target= evt.target | | Evt.srcelement;
if (!_target.getattribute ("Author") && _target!= inputobj && _target!= targetobj)
{
Getobjbyid ("Calendar"). Style.display = "None";
}
}
function DragStart (evt) {
EVT = EVT | | window.event;
var _target= evt.target | | Evt.srcelement;
if (_target.getattribute ("Author") = = "Alin_bar")
{
Dragobj = Getobjbyid ("Calendar");
Mouseoffset = Getmouseoffset (dragobj, evt);
}
}
function drag (evt)
{
EVT = EVT | | window.event;
if (dragobj)
{
var mousepos = mousecoords (evt);
DragObj.style.left = (mousepos.x-mouseoffset.x) + ' px ';
DragObj.style.top = (mousepos.y-mouseoffset.y) + ' px ';
}
}
Drag End
function Dragend (EVT)
{
Dragobj = null;
}
Document.onclick = Closecalendar;
Document.onmousedown = DragStart;
Document.onmousemove = drag;
Document.onmouseup = Dragend;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.