javascript 날짜 연동 선택 기[그 중 일부 코드 는 배 울 만하 다]

5131 단어 날짜.선택 기
DateSelector var $ = function(id) { return 'string' == typeof id ? document.getElementById(id) : id; }; var Extend = function(destination, source) { for(var pro in source) { destination[pro] = source[pro]; } return destination; } var addEvent = function(obj, type, fn) { if(obj.addEventListener) { obj.addEventListener(type, fn, false); return true; }else if(obj.attachEvent) { obj['e'+type+fn] = fn; obj[type+fn] = function(){ obj['e'+type+fn](window.event); } obj.attachEvent('on'+type, obj[type+fn]); return true; } return false; } /*! * DateSelector**Copyright(c)2009 GoodNess 2010*날짜:2009-12-15(화요일)*/function DateSelector(idYear,idMonth,idDate,options){var D=new Date();this.year = $(idYear); this.month = $(idMonth); this.date = $(idDate); this.nowYear = D.getFullYear(); this.nowMonth = D.getMonth() + 1; this.nowDate = D.getDate(); Extend(this, this.setOptions(options)); }; DateSelector.prototype={setOptions:function(options){/기본 항목 this.options={floor Year:5,//현재 연도 5 년 전 ceilYear:7,//현재 연도 후 7 년 전 Start:function(){},//선행 이벤트 onEnd:function(){}//종료 이벤트};return Extend(this.options, options || {}); }, createOption: function(container, start, end, sign){ sign = sign || start; var _num = parseInt(end-start+1, 10); container.options.length = _num; for(var i = 0; i < _num; i++) { container.options[i].text = container.options[i].value = start + i; } container.selectedIndex = (sign-start >= _num ? _num-1 : sign-start); }, getDate: function(y, m){ return new Date(y, m, 0).getDate(); }, getSelText: function(sel) { return sel.options[sel.selectedIndex].text; }, changeDate: function(bindO){ var _this = this; addEvent(bindO, 'change', function(){ var y = _this.getSelText(_this.year), m = _this.getSelText(_this.month), d = _this.getSelText(_this.date); _this.createOption(_this.date, 1, _this.getDate(y, m), d); _this.onEnd(); }); }, bindEvents: function(){ var _this = this; this.changeDate(this.year); this.changeDate(this.month); addEvent(this.date, 'change', function(){ _this.onEnd(); }); }, init: function(){ var _startYear = parseInt(this.nowYear - this.floorYear, 10); var _endYear = parseInt(this.nowYear + this.ceilYear, 10); var _endDate = this.getDate(this.nowYear, this.nowMonth, 0); this.createOption(this.year, _startYear, _endYear, this.nowYear); this.createOption(this.month, 1, 12, this.nowMonth); this.createOption(this.date, 1, _endDate, this.nowDate); this.bindEvents(); this.onStart(); } };

좋은 웹페이지 즐겨찾기