


Calendar written by jQuery (including calendar style and function)_jquery
普通调用:
按钮调用:id="button" type="button" onclick="c.showMoreDay = true; c.show(getObjById('btntxt'), '1982-1-1', this)" />
id="button3" type="button" onclick="c.showMoreDay = true; c.show(this, getObjById('btntxt3'))" />
需要的jQuery文件
function Calendar(objName)
{
this.style = {
borderColor : "#909eff", //边框颜色
headerBackColor : "#909EFF", //表头背景颜色
headerFontColor : "#ffffff", //表头字体颜色
bodyBarBackColor : "#f4f4f4", //日历标题背景色
bodyBarFontColor : "#000000", //日历标题字体色
bodyBackColor : "#ffffff", //日历背景色
bodyFontColor : "#000000", //日历字体色
bodyHolidayFontColor : "#ff0000", //假日字体色
watermarkColor : "#d4d4d4", //背景水印色
moreDayColor : "#cccccc"
};
this.showMoreDay = false; //是否显示上月和下月的日期
this.Obj = objName;
this.date = null;
this.mouseOffset = null;
this.dateInput = null;
this.timer = null;
};
Calendar.prototype.toString = function()
{
var str = this.getStyle();
str += ' ';
return str;
};
Calendar.prototype.getStyle = function()
{
var str = 'n';
return str;
};
Calendar.prototype.getHeader = function()
{
var str = '
n'; str = ' |
n'; str = ' |
0 | n';0 | n';> | n';>> |
return str;
};
Calendar.prototype.getBody = function()
{
var n = 0;
var str = this.getBodyBar();
str = '
n'; |
str = '
今天:' new Date().toFormatString("yyyy年mm月dd日") ' |
return str;
};
Calendar.prototype.getBodyBar = function()
{
var str = '
' day[i] ' | n';
return str;
}
Calendar.prototype.getYearMenu = function(year)
{
var str = '
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 '年 | n'; ||
|
var _menu = getObjById("cdrMenu");
_menu.innerHTML = str;
};
Calendar.prototype.getMonthMenu = function()
{
var str = '
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 '月 |
var _menu = getObjById("cdrMenu");
_menu.innerHTML = str;
};
Calendar.prototype.show = function()
{
if (arguments.length > 3 || arguments.length == 0)
{
alert("对不起!传入参数不对!" );
return;
}
var _date = null;
var _evObj = null;
var _initValue = null
for(i = 0; 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("传入参数错误!"); return;}
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 ? 11 : _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 {
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 {
//获取上一个月的日期
if(this.showMoreDay)
{
var _previDate = new Date(_year,_month - 1,_previDay);
_dayElement.innerHTML = _previDay;
_dayElement.title = _previDate.toFormatString("yyyy年mm月dd日");
_dayElement.value = _previDate.toFormatString("-");
_dayElement.style.color = this.style.moreDayColor;
_previDay ;
}else
{
_dayElement.innerHTML = "";
_dayElement.title = "";
}
}
else if(_day > _monthDays[_month])
{
//获取下个月的日期
if(this.showMoreDay)
{
var _nextDate = new Date(_year,_month 1,_nextDay);
_dayElement.innerHTML = _nextDay;
_dayElement.title = _nextDate.toFormatString("yyyy年mm月dd日");
_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 {
//获取本月日期
_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年mm月dd日");
_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年");
_curMonth.innerHTML = this.date.toFormatString("mm月");
_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 {
if(isnext){_year ;}else{ _year --;}
}
else
{
alert("年份超出范围(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 {
if(_month if(_month > 12) {_month = 1; _year ;}
}
else
{
alert("年份超出范围(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("浏览器不支持!");
}
}
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';
}
}
//拖动结束
function dragEnd(evt)
{
dragObj = null;
}
document.onclick = closeCalendar;
document.onmousedown = dragStart;
document.onmousemove = drag;
document.onmouseup = dragEnd;

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool