设为首页收藏本站
开启辅助访问
切换到宽版

创星网络[分享知识 传递快乐]

 找回密码
 立即注册

QQ登录

只需一步,快速开始

用新浪微博登录

只需一步,快速搞定

搜索
查看: 3995|回复: 0
打印 上一主题 下一主题

一个javascript日历,兼容多种浏览器

[复制链接]

我玩的应用:

跳转到指定楼层
楼主
发表于 2012-12-13 23:16:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  4. <title>日历演示</title>
  5. <mce:script language="javascript"><!--
  6. /****************
  7. * 由于字数限制,请下载附件看使用说明.
  8. *******如果您使用本日历控件 请保留该信息 谢谢! ***********   
  9. * http://2lin.net
  10. * Email:caoailin@gmail.com
  11. * QQ:38062022
  12. * Creation date: 2006-11-22
  13. ******************/
  14. function Calendar(objName)  
  15. {               
  16. this.style = {
  17. borderColor                       : "#909eff", //边框颜色
  18. headerBackColor                    : "#909EFF", //表头背景颜色
  19. headerFontColor                    : "#ffffff", //表头字体颜色
  20. bodyBarBackColor                  : "#f4f4f4", //日历标题背景色
  21. bodyBarFontColor                  : "#000000", //日历标题字体色
  22. bodyBackColor                     : "#ffffff", //日历背景色
  23. bodyFontColor            : "#000000", //日历字体色
  24. bodyHolidayFontColor     : "#ff0000", //假日字体色
  25. watermarkColor                     : "#d4d4d4",  //背景水印色
  26. moreDayColor             : "#cccccc"
  27. };
  28. this.showMoreDay = false; //是否显示上月和下月的日期
  29. this.Obj = objName;               
  30. this.date = null;
  31. this.mouseOffset = null;
  32. this.dateInput = null;
  33. this.timer = null;        
  34. };
  35. Calendar.prototype.toString = function()
  36. {   
  37. var str = this.getStyle();
  38. str += '<div Author="alin" class="calendar" style="display:none;" mce_style="display:none;" onselectstart="return false" oncontextmenu="return false" id="Calendar">/n';
  39. str += '<div Author="alin" class="cdrWatermark" id="cdrWatermark"></div><div id="cdrBody" style="position:absolute;left:0px;top:0px;z-index:2;width:140px;">';
  40. str += this.getHeader();
  41. str += this.getBody();   
  42. 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>';
  43. return str;
  44. };
  45. Calendar.prototype.getStyle = function()
  46. {
  47. var str = '<mce:style type="text/css"><!--
  48. /n';
  49. 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';
  50. str += '.cdrHeader{background-color:'+ this.style.headerBackColor +';width:140px;height:22px;font-size:12px;color:'+this.style.headerFontColor+';}/n';
  51. 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';
  52. str += '.cdrBodyBar{background-color:' + this.style.bodyBarBackColor + ';font-size:12px;color:' + this.style.bodyBarFontColor + ';width:140px;height:20px;}/n';
  53. str += '.cdrBody{width:140px;height:122px!important; height /**/:110px;font-size:12px;cursor:pointer;color:' + this.style.bodyFontColor + ';}/n';
  54. str += '.dayOver{height:16px;padding:0px;border:1px solid black;background-color:#f4f4f4;}/n';
  55. str += '.dayOut{padding:1px;border:none;height:16px;}/n';
  56. str += '.menuOver{background-color:'+this.style.headerBackColor+';color:'+this.style.headerFontColor+';font-size:12px;}/n';
  57. str += '.headerOver{border:1px solid black;background-color:#f4f4f4;color:black;cursor:default;}/n';
  58. str += '.cdrMenu{font-size:12px;border:1px solid #000000;background-color:#ffffff;cursor:default;width:100%}/n';
  59. str += 'html>body #Calendar{width:142px;174px;}';
  60. str += '
  61. --></mce:style><style type="text/css" mce_bogus="1">/n';
  62. 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';
  63. str += '.cdrHeader{background-color:'+ this.style.headerBackColor +';width:140px;height:22px;font-size:12px;color:'+this.style.headerFontColor+';}/n';
  64. 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';
  65. str += '.cdrBodyBar{background-color:' + this.style.bodyBarBackColor + ';font-size:12px;color:' + this.style.bodyBarFontColor + ';width:140px;height:20px;}/n';
  66. str += '.cdrBody{width:140px;height:122px!important; height /**/:110px;font-size:12px;cursor:pointer;color:' + this.style.bodyFontColor + ';}/n';
  67. str += '.dayOver{height:16px;padding:0px;border:1px solid black;background-color:#f4f4f4;}/n';
  68. str += '.dayOut{padding:1px;border:none;height:16px;}/n';
  69. str += '.menuOver{background-color:'+this.style.headerBackColor+';color:'+this.style.headerFontColor+';font-size:12px;}/n';
  70. str += '.headerOver{border:1px solid black;background-color:#f4f4f4;color:black;cursor:default;}/n';
  71. str += '.cdrMenu{font-size:12px;border:1px solid #000000;background-color:#ffffff;cursor:default;width:100%}/n';
  72. str += 'html>body #Calendar{width:142px;174px;}';
  73. str += '</style>/n';        
  74. return str;
  75. };
  76. Calendar.prototype.getHeader = function()
  77. {
  78. var str = '<table Author="alin" class="cdrHeader" cellSpacing="2" cellPadding="0"><tr Author="alin" align="center">/n';
  79. str += '<td Author="alin" onmouseover="this.className=/'headerOver/'" onmouseout="this.className=/'/'" id="previousYear" title="上一年份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeYear(false);"><<</td>/n';
  80. str += '<td Author="alin" onmouseover="this.className=/'headerOver/'" onmouseout="this.className=/'/'" id="previousMonth" title="上一月份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeMonth(false);"><</td>/n';
  81. str += '<td Author="alin" onmouseover="this.className=/'headerOver/'" id="currentYear" style="width:50px;" onclick="' + this.Obj + '.showMenu(true);" onmouseout="' + this.Obj + '.hideMenu();this.className=/'/';">0</td>/n';
  82. str += '<td Author="alin" onmouseover="this.className=/'headerOver/'" id="currentMonth" onclick="' + this.Obj + '.showMenu(false);" onmouseout="' + this.Obj + '.hideMenu();this.className=/'/';">0</td>/n';
  83. str += '<td Author="alin" onmouseover="this.className=/'headerOver/'" onmouseout="this.className=/'/'" id="nextMonth" title="下一月份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeMonth(true);">></td>/n';
  84. str += '<td Author="alin" onmouseover="this.className=/'headerOver/'" onmouseout="this.className=/'/'" id="nextYear" title="下一年份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeYear(true);">>></td></tr>/n';
  85. str += '</table>/n';
  86. return str;
  87. };
  88. Calendar.prototype.getBody = function()
  89. {
  90. var n = 0;
  91. var str = this.getBodyBar();
  92. str += '<table Author="alin" class="cdrBody" cellSpacing="2" cellPadding="0">/n';   
  93. for(i = 0; i < 6; i++)
  94. {         
  95. str += '<tr Author="alin" align="center">';
  96. for(j = 0; j < 7; j++)
  97. {
  98. str += '<td Author="alin" class="dayOut" id="cdrDay'+(n++)+'" width="13%"></td>/n';
  99. }
  100. str += '</tr>';
  101. }
  102. str += '</table>/n';
  103. str += '<table Author="alin" class="cdrBodyBar" cellSpacing="2" cellPadding="0"><tr align="center" Author="alin"><td Author="alin" style="cursor:pointer;" mce_style="cursor:pointer;" onclick="'+this.Obj+'.getToday();">今天:'+new Date().toFormatString("yyyy年mm月dd日")+'</td></tr></table>/n';
  104. return str;
  105. };
  106. Calendar.prototype.getBodyBar = function()
  107. {
  108. var str = '<table Author="alin_bar" id="cdrBodyBar" class="cdrBodyBar" style="cursor:move;" mce_style="cursor:move;" cellSpacing="2" cellPadding="0"><tr Author="alin_bar" align="center">/n';
  109. var day = new Array('日','一','二','三','四','五','六');
  110. for(i = 0; i < 7; i++)
  111. {
  112. str += '<td Author="alin_bar">' + day[i] + '</td>/n';     
  113. }
  114. str += '</tr></table>';
  115. return str;  
  116. }
  117. Calendar.prototype.getYearMenu = function(year)
  118. {
  119. var str = '<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0">/n';
  120. for(i = 0; i < 10; i++)
  121. {         
  122. var _year = year + i;
  123. var _date = new Date(_year,this.date.getMonth(),this.date.getDate());
  124. str += '<tr Author="alin" align="center"><td Author="alin" width="13%" height="16" ';
  125. if(this.date.getFullYear() != _year)
  126. {
  127. str += 'onmouseover="this.className=/'menuOver/'" onmouseout="this.className=/'/'" ';
  128. }
  129. else
  130. {
  131. str += 'class="menuOver"';
  132. }
  133. str += 'onclick="' + this.Obj + '.bindDate(/'' + _date.toFormatString("-") + '/')">' + _year + '年</td>/n';               
  134. str += '</tr>';
  135. }
  136. str += '<tr Author="alin" align="center"><td Author="alin"><table Author="alin" style="font-size:12px;width:100%;" cellSpacing="0" cellPadding="0">/n';
  137. str += '<tr Author="alin" align="center"><td Author="alin" onmouseover="this.className=/'menuOver/'" onmouseout="this.className=/'/'" onclick="'+this.Obj+'.getYearMenu('+ (year - 10) + ')"><<</td>/n';
  138. str += '<td Author="alin" onmouseover="this.className=/'menuOver/'" onmouseout="this.className=/'/'" onclick="'+this.Obj+'.getYearMenu('+ (year + 10) +')">>></td><tr>/n';
  139. str += '</table></td></tr>/n';
  140. str += '</table>';
  141. var _menu = getObjById("cdrMenu");
  142. _menu.innerHTML = str;
  143. };
  144. Calendar.prototype.getMonthMenu = function()
  145. {
  146. var str = '<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0">/n';
  147. for(i = 1; i <= 12; i++)
  148. {   
  149. var _date = new Date(this.date.getFullYear(),i-1,this.date.getDate());               
  150. str += '</tr><tr Author="alin" align="center"><td Author="alin" height="16" ';
  151. if(this.date.getMonth() + 1 != i)
  152. {
  153. str += 'onmouseover="this.className=/'menuOver/'" onmouseout="this.className=/'/'" ';
  154. }
  155. else
  156. {
  157. str += 'class="menuOver"';
  158. }
  159. str += 'onclick="' + this.Obj + '.bindDate(/'' + _date.toFormatString("-") + '/')">'+i+'月</td></tr>/n';
  160. }
  161. str += '</table>';
  162. var _menu = getObjById("cdrMenu");
  163. _menu.innerHTML = str;   
  164. };
  165. Calendar.prototype.show = function()
  166. {
  167. if (arguments.length >  3  || arguments.length == 0)
  168. {
  169. alert("对不起!传入参数不对!" );
  170. return;
  171. }   
  172. var _date = null;
  173. var _evObj = null;
  174. var _initValue = null  
  175. for(i = 0; i < arguments.length; i++)
  176. {
  177. if(typeof(arguments[i]) == "object" && arguments[i].type == "text")
  178. {_date = arguments[i];}
  179. else if(typeof(arguments[i]) == "object")
  180. {_evObj = arguments[i];}
  181. else if(typeof(arguments[i]) == "string")
  182. {_initValue = arguments[i];}  
  183. }
  184. _evObj = _evObj || _date;
  185. inputObj = _date;
  186. targetObj = _evObj
  187. if(!_date){alert("传入参数错误!"); return;}
  188. this.dateInput = _date;
  189. _date = _date.value;
  190. if(_date == "" && _initValue) _date = _initValue;   
  191. this.bindDate(_date);        
  192. var _target = getPosition(_evObj);   
  193. var _obj = getObjById("Calendar");
  194. _obj.style.display = "";
  195. _obj.style.left = _target.x + 'px';
  196. if((document.body.clientHeight - (_target.y + _evObj.clientHeight)) >= _obj.clientHeight)
  197. {        
  198. _obj.style.top = (_target.y + _evObj.clientHeight) + 'px';
  199. }
  200. else
  201. {         
  202. _obj.style.top = (_target.y - _obj.clientHeight) + 'px';
  203. }
  204. };
  205. Calendar.prototype.hide = function()
  206. {
  207. var obj = getObjById("Calendar");
  208. obj.style.display = "none";   
  209. };
  210. Calendar.prototype.bindDate = function(date)
  211. {
  212. var _monthDays = new Array(31,30,31,30,31,30,31,31,30,31,30,31);        
  213. var _arr = date.split('-');               
  214. var _date = new Date(_arr[0],_arr[1]-1,_arr[2]);        
  215. if(isNaN(_date)) _date = new Date();        
  216. this.date = _date;
  217. this.bindHeader();        
  218. var _year = _date.getFullYear();
  219. var _month = _date.getMonth();
  220. var _day = 1;        
  221. var _startDay = new Date(_year,_month,1).getDay();
  222. var _previYear = _month == 0 ? _year - 1 : _year;
  223. var _previMonth = _month == 0 ? 11 : _month - 1;
  224. var _previDay = _monthDays[_previMonth];
  225. if (_previMonth == 1) _previDay =((_previYear%4==0)&&(_previYear%100!=0)||(_previYear%400==0))?29:28;        
  226. _previDay -= _startDay - 1;
  227. var _nextDay = 1;
  228. _monthDays[1] = ((_year%4==0)&&(_year%100!=0)||(_year%400==0))?29:28;
  229. for(i = 0; i < 40; i++)
  230. {        
  231. var _dayElement = getObjById("cdrDay" + i);
  232. _dayElement.onmouseover = Function(this.Obj + ".onMouseOver(this)");
  233. _dayElement.onmouseout = Function(this.Obj + ".onMouseOut(this)");
  234. _dayElement.onclick = Function(this.Obj + ".onClick(this)");
  235. this.onMouseOut(_dayElement);                        
  236. _dayElement.style.color = "";
  237. if(i < _startDay)
  238. {
  239. //获取上一个月的日期
  240. if(this.showMoreDay)
  241. {
  242. var _previDate = new Date(_year,_month - 1,_previDay);
  243. _dayElement.innerHTML = _previDay;
  244. _dayElement.title = _previDate.toFormatString("yyyy年mm月dd日");
  245. _dayElement.value = _previDate.toFormatString("-");        
  246. _dayElement.style.color = this.style.moreDayColor;        
  247. _previDay++;
  248. }else
  249. {
  250. _dayElement.innerHTML = "";
  251. _dayElement.title = "";
  252. }
  253. }
  254. else if(_day > _monthDays[_month])
  255. {
  256. //获取下个月的日期
  257. if(this.showMoreDay)
  258. {
  259. var _nextDate = new Date(_year,_month + 1,_nextDay);
  260. _dayElement.innerHTML = _nextDay;
  261. _dayElement.title = _nextDate.toFormatString("yyyy年mm月dd日");
  262. _dayElement.value = _nextDate.toFormatString("-");
  263. _dayElement.style.color = this.style.moreDayColor;        
  264. _nextDay++;                           
  265. }else
  266. {
  267. _dayElement.innerHTML = "";
  268. _dayElement.title = "";
  269. }
  270. }
  271. else if(i >= new Date(_year,_month,1).getDay() && _day <= _monthDays[_month])
  272. {
  273. //获取本月日期
  274. _dayElement.innerHTML = _day;
  275. if(_day == _date.getDate())
  276. {
  277. this.onMouseOver(_dayElement);
  278. _dayElement.onmouseover = Function("");   
  279. _dayElement.onmouseout = Function("");                                                                       
  280. }
  281. if(this.isHoliday(_year,_month,_day))
  282. {
  283. _dayElement.style.color = this.style.bodyHolidayFontColor;                          
  284. }
  285. var _curDate = new Date(_year, _month, _day);
  286. _dayElement.title =  _curDate.toFormatString("yyyy年mm月dd日");
  287. _dayElement.value = _curDate.toFormatString("-");
  288. _day++;
  289. }
  290. else
  291. {
  292. _dayElement.innerHTML = "";
  293. _dayElement.title = "";
  294. }        
  295. }
  296. var _menu = getObjById("cdrMenu");
  297. _menu.style.display = "none";        
  298. };
  299. Calendar.prototype.bindHeader = function()
  300. {
  301. var _curYear = getObjById("currentYear");
  302. var _curMonth = getObjById("currentMonth");
  303. var _watermark = getObjById("cdrWatermark");
  304. _curYear.innerHTML = this.date.toFormatString("yyyy年");
  305. _curMonth.innerHTML =  this.date.toFormatString("mm月");
  306. _watermark.innerHTML = this.date.getFullYear();     
  307. };        
  308. Calendar.prototype.getToday = function()
  309. {
  310. var _date = new Date();
  311. this.bindDate(_date.toFormatString("-"));
  312. };        
  313. Calendar.prototype.isHoliday = function(year,month,date)
  314. {
  315. var _date = new Date(year,month,date);
  316. return (_date.getDay() == 6 || _date.getDay() == 0);
  317. };
  318. Calendar.prototype.onMouseOver = function(obj)
  319. {
  320. obj.className = "dayOver";
  321. };
  322. Calendar.prototype.onMouseOut = function(obj)
  323. {
  324. obj.className = "dayOut";
  325. };        
  326. Calendar.prototype.onClick = function(obj)
  327. {  
  328. if(obj.innerHTML != "")  this.dateInput.value = obj.value;
  329. this.hide();
  330. };
  331. Calendar.prototype.onChangeYear = function(isnext)
  332. {
  333. var _year = this.date.getFullYear();
  334. var _month = this.date.getMonth() + 1;
  335. var _date = this.date.getDate();
  336. if(_year > 999 && _year <10000)
  337. {
  338. if(isnext){_year++;}else{ _year --;}
  339. }
  340. else
  341. {
  342. alert("年份超出范围(1000-9999)!");
  343. }
  344. this.bindDate(_year + '-' + _month + '-' + _date);
  345. };
  346. Calendar.prototype.onChangeMonth = function(isnext)
  347. {
  348. var _year = this.date.getFullYear();
  349. var _month = this.date.getMonth() + 1;
  350. var _date = this.date.getDate();
  351. if(isnext){ _month ++;} else {_month--;}
  352. if(_year > 999 && _year <10000)
  353. {
  354. if(_month < 1) {_month = 12; _year--;}
  355. if(_month > 12) {_month = 1; _year++;}
  356. }
  357. else
  358. {
  359. alert("年份超出范围(1000-9999)!");
  360. }  
  361. this.bindDate(_year + '-' + _month + '-' + _date);
  362. };
  363. Calendar.prototype.showMenu = function(isyear)
  364. {
  365. var _menu = getObjById("cdrMenu");
  366. if(isyear != null)
  367. {   
  368. var _obj = (isyear)? getObjById("currentYear") : getObjById("currentMonth");
  369. if(isyear)
  370. {
  371. this.getYearMenu(this.date.getFullYear() - 5);           
  372. }
  373. else
  374. {
  375. this.getMonthMenu();           
  376. }
  377. _menu.style.top = (_obj.offsetTop + _obj.offsetHeight) + 'px';
  378. _menu.style.left = _obj.offsetLeft + 'px';        
  379. _menu.style.width = _obj.offsetWidth + 'px';
  380. }
  381. if (this.timer != null) clearTimeout(this.timer);
  382. _menu.style.display="";
  383. }
  384. Calendar.prototype.hideMenu = function()
  385. {
  386. var _obj = getObjById("cdrMenu");
  387. this.timer = window.setTimeout(function(){_obj.style.display='none';},500);        
  388. }
  389. Number.prototype.NaN0 = function()
  390. {
  391. return isNaN(this) ? 0 : this;
  392. }
  393. Date.prototype.toFormatString = function(fs)
  394. {
  395. if(fs.length == 1)
  396. {
  397. return this.getFullYear() + fs + (this.getMonth() + 1) + fs + this.getDate();
  398. }
  399. fs = fs.replace("yyyy",this.getFullYear());
  400. fs = fs.replace("mm",(this.getMonth() + 1));
  401. fs = fs.replace("dd",this.getDate());
  402. return fs;
  403. }
  404. /************公用方法及变量**************/
  405. var inputObj = null;
  406. var targetObj = null;        
  407. var dragObj = null;
  408. var mouseOffset = null;
  409. function getObjById(obj)
  410. {
  411. if(document.getElementById)
  412. {
  413. return document.getElementById(obj);
  414. }
  415. else
  416. {
  417. alert("浏览器不支持!");
  418. }
  419. }
  420. function mouseCoords(ev)
  421. {
  422. if(ev.pageX || ev.pageY){
  423. return {x:ev.pageX, y:ev.pageY};
  424. }
  425. return {
  426. x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
  427. y:ev.clientY + document.body.scrollTop  - document.body.clientTop
  428. };
  429. }
  430. function getPosition(e)
  431. {
  432. var left = 0;
  433. var top  = 0;
  434. while (e.offsetParent){
  435. left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
  436. top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
  437. e     = e.offsetParent;
  438. }
  439. left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
  440. top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
  441. return {x:left, y:top};
  442. }
  443. function getMouseOffset(target, ev)
  444. {
  445. ev = ev || window.event;
  446. var docPos    = getPosition(target);
  447. var mousePos  = mouseCoords(ev);
  448. return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
  449. }
  450. function closeCalendar(evt){
  451. evt = evt || window.event;
  452. var _target= evt.target || evt.srcElement;
  453. if(!_target.getAttribute("Author") &&  _target != inputObj && _target != targetObj)
  454. {
  455. getObjById("Calendar").style.display = "none";           
  456. }  
  457. }
  458. function dragStart(evt){
  459. evt = evt || window.event;        
  460. var _target= evt.target || evt.srcElement;
  461. if(_target.getAttribute("Author") == "alin_bar")
  462. {           
  463. dragObj = getObjById("Calendar");           
  464. mouseOffset = getMouseOffset(dragObj, evt);         
  465. }   
  466. }
  467. function drag(evt)
  468. {
  469. evt =  evt || window.event;        
  470. if(dragObj)
  471. {                  
  472. var mousePos = mouseCoords(evt);
  473. dragObj.style.left = (mousePos.x - mouseOffset.x) + 'px';
  474. dragObj.style.top  = (mousePos.y - mouseOffset.y) + 'px';         
  475. }
  476. }
  477. //拖动结束
  478. function dragEnd(evt)
  479. {
  480. dragObj = null;   
  481. }
  482. /***********End 公用方法*********/
  483. document.onclick = closeCalendar;
  484. document.onmousedown = dragStart;
  485. document.onmousemove = drag;
  486. document.onmouseup = dragEnd;
  487. /*********结束**********/
  488. // --></mce:script>
  489. </head>
  490. <body>
  491. <form id="Form1">
  492. <mce:script type="text/javascript"><!--
  493. var c = new Calendar("c");
  494. document.write(c);
  495. // --></mce:script>
  496. 普通调用:<input type="text" name="txt"  onfocus="c.showMoreDay = false;c.show(this,'1980-01-01');"/><input type="text" name="txt1"  onfocus="c.showMoreDay = false;c.show('1981-01-01',this);"/><input type="text" name="txt2"  onfocus="c.showMoreDay = false;c.show(this);"/>
  497. <div style="height:300px"></div> 按钮调用:<input type="text" name="btntxt" id="btntxt" /><input name="button" value="*" id="button" type="button" onclick="c.showMoreDay = true;c.show(getObjById('btntxt'),'1982-1-1',this)"/> <input type="text" name="btntxt1" id="btntxt1" /><input name="button1"  value="*"  id="button1" type="button" onclick="c.showMoreDay = true;c.show(getObjById('btntxt1'),this,'1983-1-1')"/>


  498.    <input type="text" name="btntxt3" id="btntxt3" /><input name="button3" value="*"  id="button3" type="button" onclick="c.showMoreDay = true;c.show(this,getObjById('btntxt3'))"/></form></body>
  499. </html>
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|创星网络 ( 苏ICP备11027519号|网站地图  

GMT+8, 2024-5-2 18:59 , Processed in 0.089102 second(s), 28 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表