<머리>
日期控件
<스크립트>
var agt = navigator.userAgent.toLowerCase();
var OldTextBox;
함수 DateSeter(obj){
var parent=obj.parentNode;
var selYear=document.createElement('SELECT');
selYear.id='LoftyYear';
parent.insertBefore(selYear,obj);
var selMonth=document.createElement('SELECT');
selMonth.id='LoftyMonth';
parent.insertBefore(selMonth,obj);
var selDay=document.createElement('SELECT');
selDay.id='LoftyDay';
parent.insertBefore(selDay,obj);
var btnSubmit=document.createElement('BUTTON');
btnSubmit.style.width='22px';
parent.insertBefore(btnSubmit,obj);
btnSubmit.id='LoftyBtn';
for(s in btnSubmit)
{
//document.write(s '
');
}
btnSubmit.textContent='확인';
btnSubmit.value='확인';
al(btnSubmit,'click','Restore()');
OldTextBox=obj;
parent.removeChild(obj);
var now=new Date();
var cYear=now.getFullYear();
SetCurrentYear(selYear,cYear);
al(selYear,'change','SetCurrentYear(document.getElementById('LoftyYear'))');
al(selMonth,'change','SetDay(null,null)');
for(i=1;i<=12;i )
{
var op=new Option(i,i);
selMonth.options.add(op);
}
var cMonth=now.getMonth() 1;
SetDay(cYear,cMonth);
selDay.selectedIndex=now.getDate()-1;
}
함수 Restore()
{
var yy=document.getElementById('LoftyYear');
var mm=document.getElementById('LoftyMonth');
var d=document.getElementById('LoftyDay');
var btn=document.getElementById('LoftyBtn');
var time=yy.options[yy.selectedIndex].value '-' mm.options[mm.selectedIndex].value '-' d.options[d.selectedIndex].value;
OldTextBox.value=time;
var parent=yy.parentNode;
parent.insertBefore(OldTextBox,yy);
parent.removeChild(yy);
parent.removeChild(mm);
parent.removeChild(d);
parent.removeChild(btn);
}
함수 SetDay(년,월)
{
if(year==null){
var yy=document.getElementById('LoftyYear');
var mm=document.getElementById('LoftyMonth');
연도=Math.round(yy.options[yy.selectedIndex].value);
월=Math.round(mm.options[mm.selectedIndex].value);
}
var date=new 날짜(년,월,1);
date.setDate(0);
var maxdate=date.getDate();
var obj=document.getElementById('LoftyDay');
var seldate=obj.selectedIndex;
if(obj.options.length>0){
if(Math.round(obj.options[obj.selectedIndex].value)>maxdate)
{
seldate=maxdate-1 ;
}
}
reAppendSelect(obj,1,maxdate,seldate 1);
}
함수 SetCurrentYear(selecter,currYear)
{
if(currYear==null){
currYear=Math.round(selecter.options[selecter.selectedIndex].value);
}
reAppendSelect(selecter,currYear-10,currYear 10,currYear);
}
함수 reAppendSelect(selecter,startIndex,endIndex,selIndex)
{
while(selecter.options.length>0)
{
selecter.removeChild(selecter.options[ 선택기.옵션.길이-1]);
}
for(i=startIndex;i<=endIndex;i )
{
var op=new Option(i,i);
selecter.options.add(op);
op.selected=(selIndex==i);
}
}
함수 al(obj,lissener,func){
if(agt.indexOf('firefox')!=-1){
obj.addEventListener(lissener,function (){eval(func);},false);
}else{
obj.attachEvent('on' lissener,function(){eval(func);});
}
}
<본문>