复制代码 代码如下:
<html>
<head>
<title>js calendar</title>
<script language=”javascript”>
/* copyright mihai bazon, 2002-2005 | www.bazon.net/mishoo
* ———————————————————–
*
* the dhtml calendar, version 1.0 “it is happening again”
*
* details and latest version at:
* www.dynarch.com/projects/calendar
*
* this script is developed by dynarch.com. visit us at www.dynarch.com.
*
* this script is distributed under the gnu lesr general public licen.
* read the entire licen text here: http://www.gnu.org/licens/lgpl.html
*/
// $id: calendar.js,v 1.51 2005/03/07 16:44:31 mishoo exp $
/** the calendar object constructor. */
calendar = function (firstdayofweek, datestr, onlected, onclo) {
// member variables
this.activediv = null;
this.currentdateel = null;
this.getdatestatus = null;
this.getdatetooltip = null;
this.getdatetext = null;
this.timeout = null;
this.onlected = onlected || null;
this.onclo = onclo || null;
this.dragging = fal;
this.hidden = fal;
this.minyear = 1970;
this.maxyear = 2050;
this.dateformat = calendar._tt[“def_date_format”];
this.ttdateformat = calendar._tt[“tt_date_format”];
this.ispopup = true;
this.weeknumbers = true;
this.firstdayofweek = typeof firstdayofweek == “number” ? firstdayofweek : calendar._fd; // 0 for sunday, 1 for monday, etc.
this.showsothermonths = fal;
this.datestr = datestr;
this.ar_days = null;
this.showstime = fal;
this.time24 = true;
this.yearstep = 2;
this.hilitetoday = true;
this.multiple = null;
// html elements
this.table = null;
this.element = null;
this.tbody = null;
this.firstdayname = null;
// combo boxes
this.monthscombo = null;
this.yearscombo = null;
this.hilitedmonth = null;
this.activemonth = null;
this.hilitedyear = null;
this.activeyear = null;
// i人文类nformation
this.dateclicked = fal;
// one-time initializations
if (typeof calendar._sdn == “undefined”) {
// table of short day names
if (typeof calendar._sdn_len == “undefined”)
calendar._sdn_len = 3;
var ar = new array();
for (var i = 8; i > 0;) {
ar[–i] = calendar._dn[i].substr(0, calendar._sdn_len);
}
calendar._sdn = ar;
// table of short month names
if (typeof calendar._smn_len == “undefined”)
calendar._smn_len = 3;
ar = new array();
for (var i = 12; i > 0;) {
ar[–i] = calendar._mn[i].substr(0, calendar._smn_len);
}
calendar._smn = ar;
}
};
// ** constants
/// “static”, needed for event handlers.
calendar._c = null;
/// detect a special ca of “web browr”
calendar.is_ie = ( /msie/i.test(navigator.uragent) &&
!/opera/i.test(navigator.uragent) );
calendar.is_ie5 = ( calendar.is_ie && /msie 5\.0/i.test(navigator.uragent) );
/// detect opera browr
calendar.is_opera = /opera/i.test(navigator.uragent);
/// detect khtml-bad browrs
calendar.is_khtml = /konqueror|safari|khtml/i.test(navigator.uragent);
// begin: utility functions; beware that the might be moved into a parate
// library, at some point.
calendar.getabsolutepos = function(el) {
var sl = 0, st = 0;
var is_div = /^div$/i.test(el.tagname);
if (is_div && el.scrollleft)
sl = el.scrollleft;
if (is_div && el.scrolltop)
st = el.scrolltop;
var r = { x: el.offtleft – sl, y: el.offttop – st };
if (el.offtparent) {
var tmp = this.getabsolutepos(el.offtparent);
r.x += tmp.x;
r.y += tmp.y;
}
return r;
};
calendar.isrelated = function (el, evt) {
var related = evt.relatedtarget;
if (!related) {
var type = evt.type;
if (type == “mouover”) {
related = evt.fromelement;
} el if (type == “mouout”) {
related = evt.toelement;
}
}
while (related) {
if (related == el) {
return true;
}
related = related.parentnode;
}
return fal;
};
calendar.removeclass = function(el, classname) {
if (!(el && el.classname)) {
return;
}
var cls = el.classname.split(” “);
var ar = new array();
for (var i = cls.length; i > 0;) {
if (cls[–i] != classname) {
ar[ar.length] = cls[i];
}
}
el.classname = ar.join(” “);
};
calendar.addclass = function(el, classname) {
calendar.removeclass(el, classname);
el.classname += ” ” + classname;
};
// fixme: the following 2 functions totally suck, are uless and should be replaced immediately.
calendar.getelement = function(ev) {
var f = calendar.is_ie ? window.event.srcelement : ev.current小时代电影好看吗target;
while (f.nodetype != 1 || /^div$/i.test(f.tagname))
f = f.parentnode;
return f;
};
calendar.gettargetelement = function(ev) {
var f = calendar.is_ie ? window.event.srcelement : ev.target;
while (f.nodetype != 1)
f = f.parentnode;
return f;
};
calendar.stopevent = function(ev) {
ev || (ev = window.event);
if (calendar.is_ie) {
ev.cancelbubble = true;
ev.returnvalue = fal;
} el {
ev.preventdefault();
ev.stoppropagation();
}
return fal;
};
calendar.addevent = function(el, evname, func) {
if (el.attachevent) { // ie
el.attachevent(“on” + evname, func);
} el if (el.addeventlistener) { // gecko / w3c
el.addeventlistener(evname, func, true);
} el {
el[“on” + evname] = func;
}
};
calendar.removeevent = function(el, evname, func) {
if (el.detachevent) { // ie
el.detachevent(“on” + evname, func);
} el if (el.removeeventlistener) { // gecko / w3c
el.removeeventlistener(evname, func, true);
} el {
el[“on” + evname] = null;
}
};
calendar.createelement = function(type, parent) {
var el = null;
if (document.createelementns) {
// u the xhtml namespace; ie won’t normally get here unless
// _they_ “fix” the dom2 implementation.
el = document.createelementns(“http://www.w3.org/1999/xhtml”, type);
} el {
el = document.createelement(type);
}
if (typeof parent != “undefined”) {
parent.appendchild(el);
}
return el;
};
// end: utility functions
// begin: calendar static functions
/** internal — adds a t of events to make some element behave like a button. */
calendar._add_evs = function(el) {
with (calendar) {
addevent(el, “mouover”, daymouover);
addevent(el, “moudown”, daymoudown);
addevent(el, “mouout”, daymouout);
if (is_ie) {
addevent(el, “dblclick”, daymoudblclick);
el.tattribute(“unlectable”, true);
}
}
};
calendar.findmonth = function(el) {
if (typeof el.month != “undefined”) {
return el;
} el if (typeof el.parentnode.month != “undefined”) {
return el.parentnode;
}
return null;
};
calendar.findyear = function(el) {
if (typeof el.year != “undefined”) {
return el;
} el if (typeof el.parentnode.year != “undefined”) {
return el.parentnode;
}
return null;
};
calendar.showmonthscombo = function () {
var cal = calendar._c;
if (!cal) {
return fal;
}
var cal = cal;
var cd = cal.activediv;
var mc = cal.monthscombo;
if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, “hilite”);
}
if (cal.activemonth) {
calendar.removeclass(cal.activemonth, “active”);
}
var mon = cal.monthscombo.getelementsbytagname(“div”)[cal.date.getmonth()];
calendar.addclass(mon, “active”);
cal.activemonth = mon;
var s = mc.style;
s.display = “block”;
if (cd.navtype < 0)
s.left = cd.offtleft + “px”;
el {
var mcw = mc.offtwidth;
if (typeof mcw == “undefined”)
// konqueror brain-dead techniques
mcw = 50;
s.left = (cd.offtleft + cd.offtwidth – mcw) + “px”;
}
s.top = (cd.offttop + cd.offtheight) + “px”;
};
calendar.showyearscombo = function (fwd) {
var cal = calendar._c;
if (!cal) {
return fal;
}
var cal = cal;
var cd = cal.activediv;
var yc = cal.yearscombo;
if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, “hilite”);
}
if (cal.activeyear) {
calendar.removeclass(cal.activeyear, “active”);
}
cal.activeyear = null;
var y = cal.date.getfullyear() + (fwd ? 1 : -1);
var yr = yc.firstchild;
var show = fal;
for (var i = 12; i > 0; –i) {
if (y >= cal.minyear && y <= cal.maxyear) {
yr.innerhtml = y;
yr.year = y;
yr.style.display = “block”;
show = true;
} el {
yr.style.display = “none”;
}
yr = yr.nextsibling;
y += fwd ? cal.yearstep : -cal.yearstep;
}
if (show) {
var s = yc.style;
s.display = “block”;
if (cd.navtype < 0)
s.left = cd.offtleft + “px”;
el {
var ycw = yc.offtwidth;
if (typeof ycw == “undefined”)
// konqueror brain-dead techniques
ycw = 50;
s.left = (cd.offtleft + cd.offtwidth – ycw) + “px”;
}
s.top = (cd.offttop + cd.offtheight) + “px”;
}
};
// event handlers
calendar.tablemouup = function(ev) {
var cal = calendar._c;
if (!cal) {
return fal;
}
if (cal.timeout) {
cleartimeout(cal.timeout);
}
var el = cal.activediv;
if (!el) {
return fal;
}
var target = calendar.gettargetelement(ev);
ev || (ev = window.event);
calendar.removeclass(el, “active”);
if (target == el || target.parentnode == el) {
calendar.cellclick(el, ev);
}
var mon = calendar.findmonth(target);
var date = null;
if (mon) {
date = new date(cal.date);
if (mon.month != date.getmonth()) {
date.tmonth(mon.month);
cal.tdate(date);
cal.dateclicked = fal;
cal.callhandler();
}
} el {
var year = calendar.findyear(target);
if (year) {
date = new date(cal.date);
if (year.year != date.getfullyear()) {
date.tfullyear(year.year);
cal.tdate(date);
cal.dateclicked = fal;
cal.callhandler();
}
}
}
with (calendar) {
removeevent(document, “mouup”, tablemouup);
removeevent(document, “mouover”, tablemouover);
removeevent(document, “moumove”, tablemouover);
cal._hidecombos();
_c = null;
return stopevent(ev);
}
};
calendar.tablemouover = function (ev) {
var cal = calendar._c;
if (!cal) {
return;
}
var el = cal.activediv;
var target = calendar.gettargetelement(ev);
if (target == el || target.parentnode == el) {
calendar.addclass(el, “hilite active”);
calendar.addclass(el.parentnode, “rowhilite”);
} el {
if (typeof el.navtype == “undefined” || (el.navtype != 50 && (el.navtype == 0 || math.abs(el.navtype) > 2)))
calendar.removeclass(el, “active”);
calendar.removeclass(el, “hilite”);
calendar.removeclass(el.parentnode, “rowhilite”);
}
ev || (ev = window.event);
if (el.navtype == 50 && target != el) {
var pos = calendar.getabsolutepos(el);
var w = el.offtwidth;
var x = ev.clientx;
var dx;
var decrea = true;
if (x > pos.x + w) {
dx = x – pos.x – w;
decrea = fal;
} el
dx = pos.x – x;
if (dx < 0) dx = 0;
var range = el._range;
var current = el._current;
var count = math.floor(dx / 10) % range.length;
for (var i = range.length; –i >= 0;)
if (range[i] == current)
break;
while (count– > 0)
if (decrea) {
if (–i < 0)
i = range.length – 1;
} el if ( ++i >= range.length )
i = 0;
var newval = range[i];
el.innerhtml = newval;
cal.onupdatetime();
}
var mon = calendar.findmonth(target);
if (mon) {
if (mon.month != cal.date.getmonth()) {
if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, “hilite”);
}
calendar.addclass(mon, “hilite”);
cal.hilitedmonth = mon;
} el if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, “hilite”);
}
} el {
if (cal.hilitedmonth) {
calendar.removeclass(cal.hilitedmonth, “hilite”);
}
var year = calendar.findyear(target);
if (year) {
if (year.year != cal.date.getfullyear()) {
if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, “hilite”);
}
calendar.addclass(year, “hilite”);
cal.hilitedyear = year;
} el if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, “hilite”);
}
} el if (cal.hilitedyear) {
calendar.removeclass(cal.hilitedyear, “hilite”);
}
}
return calendar.stopevent(ev);
};
calendar.tablemoudown = function (ev) {
if (calendar.gettargetelement(ev) == calendar.getelement(ev)) {
return calendar.stopevent(ev);
}
};
calendar.caldragit = function (ev) {
var cal = calendar._c;
if (!(cal && cal.dragging)) {
return fal;
}
var posx;
var posy;
if (calendar.is_ie) {
posy = window.event.clienty + document.body.scrolltop;
posx = window.event.clientx + document.body.scrollleft;
} el {
posx = ev.pagex;
posy = ev.pagey;
}
cal.hideshowcovered();
var st = cal.element.style;
st.left = (posx – cal.xoffs) + “px”;
st.top = (posy – cal.yoffs) + “px”;
return calendar.stopevent(ev);
};
calendar.caldragend = function (ev) {
var cal = calendar._c;
if (!cal) {
return fal;
}
cal.dragging = fal;
with (calendar) {
removeevent(document, “moumove”, caldragit);
removeevent(document, “mouup”, caldragend);
tablemouup(ev);
}
cal.hideshowcovered();
};
calendar.daymoudown = function(ev) {
var el = calendar.getelement(ev);
if (el.disabled) {
return fal;
}
var cal = el.calendar;
cal.activediv = el;
calendar._c = cal;
if (el.navtype != 300) with (calendar) {
if (el.navtype == 50) {
el._current = el.innerhtml;
addevent(document, “moumove”, tablemouover);
} el
addevent(document, calendar.is_ie5 ? “moumove” : “mouover”, tablemouover);
addclass(el, “hilite active”);
addevent(document, “mouup”, tablemouup);
} el if (cal.ispopup) {
cal._dragstart(ev);
}
if (el.navtype == -1 || el.navtype == 1) {
if (cal.timeout) cleartimeout(cal.timeout);
cal.timeout = ttimeout(“calendar.showmonthscombo()”, 250);
} el if (el.navtype == -2 || el.navtype == 2) {
if (cal.timeout) cleartimeout(cal.timeout);
cal.timeout = ttimeout((el.navtype > 0) ? “calendar.showyearscombo(true)” : “calendar.showyearscombo(fal)”, 250);
} el {
cal.timeout = null;
}
return calendar.stopevent(ev);
};
calendar.daymoudblclick = function(ev) {
calendar.cellclick(calendar.getelement(ev), ev || window.event);
if (calendar.is_ie) {
document.lection.empty();
}
};
calendar.daymouover = function(ev) {
var el = calendar.getelement(ev);
if (calendar.isrelated(el, ev) || calendar._c || el.disabled) {
return fal;
}
if (el.ttip) {
if (el.ttip.substr(0, 1) == “_”) {
el.ttip = el.caldate.print(el.calendar.ttdateformat) + el.ttip.substr(1);
}
el.calendar.tooltips.innerhtml = el.ttip;
}
if (el.navtype != 300) {
calendar.addclass(el, “hilite”);
if (el.caldate) {
calendar.addclass(el.parentnode, “rowhilite”);
}
}
return calendar.stopevent(ev);
};
calendar.daymouout = function(ev) {
with (calendar) {
var el = getelement(ev);
if (isrelated(el, ev) || _c || el.disabled)
return fal;
removeclass(el, “hilite”);
if (el.caldate)
removeclass(el.parentnode, “rowhilite”);
if (el.calendar)
el.calendar.tooltips.innerhtml = _tt[“l_date”];
return stopevent(ev);
}
};
/**
* a generic “click” handler
本文发布于:2023-04-06 14:07:58,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/946e47519349e861716fb1154d258e0a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:php+javascript的日历控件.doc
本文 PDF 下载地址:php+javascript的日历控件.pdf
留言与评论(共有 0 条评论) |