日期:2014-05-19  浏览次数:20536 次

如何制作这样的calender控件?
我是新手,还没写过用户控件(不知道这里能否贴图   把图放在了我的空间里http://hiphotos.baidu.com/zeratul%5Fbb/pic/item/0114478d4c573816b31bba59.jpg)   那个today实现textbox中出现当前日期,格式为yy-MM-dd。   求实现这样一个个控件的代码。

------解决方案--------------------
给你一个Calendar.js

/* Copyright Mihai Bazon, 2002 | http://students.infoiasi.ro/~mishoo
* ---------------------------------
*
* The DHTML Calendar, version 0.9.2 "The art of date selection "
*
* Details and latest version at:
* http://students.infoiasi.ro/~mishoo/site/calendar.epl
*
* Feel free to use this script under the terms of the GNU Lesser General
* Public License, as long as you do not remove or alter this notice.
*/

// $Id: calendar.js,v 1.7 2003/02/13 11:19:45 mbazon Exp $

/** The Calendar object constructor. */
Calendar = function (mondayFirst, dateStr, onSelected, onClose) {
// member variables
this.activeDiv = null;
this.currentDateEl = null;
this.checkDisabled = null;
this.timeout = null;
this.onSelected = onSelected || null;
this.onClose = onClose || null;
this.dragging = false;
this.hidden = false;
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.mondayFirst = mondayFirst;
this.dateStr = dateStr;
this.ar_days = 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;

// one-time initializations
if (!Calendar._DN3) {
// table of short day names
var ar = new Array();
for (var i = 8; i > 0;) {
ar[--i] = Calendar._DN[i].substr(0, 3);
}
Calendar._DN3 = ar;
// table of short month names
ar = new Array();
for (var i = 12; i > 0;) {
ar[--i] = Calendar._MN[i].substr(0, 3);
}
Calendar._MN3 = ar;
}
};

// ** constants

/// "static ", needed for event handlers.
Calendar._C = null;

/// detect a special case of "web browser "
Calendar.is_ie = ( (navigator.userAgent.toLowerCase().indexOf( "msie ") != -1) &&
(navigator.userAgent.toLowerCase().indexOf( "opera ") == -1) );

// short day names array (initialized at first constructor call)
Calendar._DN3 = null;

// short month names array (initialized at first constructor call)
Calendar._MN3 = null;

// BEGIN: UTILITY FUNCTIONS; beware that these might be moved into a separate
// library, at some point.

Calendar.getAbsolutePos = function(el) {
var r = { x: el.offsetLeft, y: el.offsetTop };
if (el.offsetParent) {
var tmp = Calendar.getAbsolutePos(el.offsetParent);
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 == "mouseover ") {
related = evt.fromElement;
} else if (type == "mouseout ") {
related = evt.toElement;
}
}
while (related) {
if (related == el) {
return true;