日期控件 <script> <br>var agt = navigator.userAgent.toLowerCase(); <br>var OldTextBox; <br>function DateSeter(obj){ <br> var parent=obj.parentNode; <br><br> var selYear=document.createElement('SELECT'); <br> selYear.id='LoftyYear'; <br> parent.insertBefore(selYear,obj); <br> var selMonth=document.createElement('SELECT'); <br> selMonth.id='LoftyMonth'; <br> parent.insertBefore(selMonth,obj); <br> var selDay=document.createElement('SELECT'); <br> selDay.id='LoftyDay'; <br> parent.insertBefore(selDay,obj); <br> var btnSubmit=document.createElement('BUTTON'); <br> btnSubmit.style.width='22px'; <br> parent.insertBefore(btnSubmit,obj); <br> btnSubmit.id='LoftyBtn'; <br> for(s in btnSubmit) <br> { <br>//document.write(s '<br />'); <br> } <br> btnSubmit.textContent='OK'; <br> btnSubmit.value='OK'; <br> al(btnSubmit,'click','Restore()'); <br> OldTextBox=obj; <br> parent.removeChild(obj); <br><br> var now=new Date(); <br> var cYear=now.getFullYear(); <br> SetCurrentYear(selYear,cYear); <br> al(selYear,'change','SetCurrentYear(document.getElementById('LoftyYear'))'); <br> al(selMonth,'change','SetDay(null,null)'); <br> for(i=1;i<=12;i ) <BR> { <BR> var op=new Option(i,i); <BR> selMonth.options.add(op); <BR> } <BR> var cMonth=now.getMonth() 1; <BR> SetDay(cYear,cMonth); <BR> selDay.selectedIndex=now.getDate()-1; <BR>} <BR>function Restore() <BR>{ <BR> var yy=document.getElementById('LoftyYear'); <BR> var mm=document.getElementById('LoftyMonth'); <BR> var d=document.getElementById('LoftyDay'); <BR> var btn=document.getElementById('LoftyBtn'); <BR> var time=yy.options[yy.selectedIndex].value '-' mm.options[mm.selectedIndex].value '-' d.options[d.selectedIndex].value; <BR> OldTextBox.value=time; <BR> var parent=yy.parentNode; <BR> parent.insertBefore(OldTextBox,yy); <BR> parent.removeChild(yy); <BR> parent.removeChild(mm); <BR> parent.removeChild(d); <BR> parent.removeChild(btn); <BR>} <BR>function SetDay(year,month) <BR>{ <BR> if(year==null){ <BR> var yy=document.getElementById('LoftyYear'); <BR> var mm=document.getElementById('LoftyMonth'); <BR> year=Math.round(yy.options[yy.selectedIndex].value); <BR> month=Math.round(mm.options[mm.selectedIndex].value); <BR> } <BR> var date=new Date(year,month,1); <BR> date.setDate(0); <BR> var maxdate=date.getDate(); <BR> var obj=document.getElementById('LoftyDay'); <BR> var seldate=obj.selectedIndex; <BR> if(obj.options.length>0){ <br> if(Math.round(obj.options[obj.selectedIndex].value)>maxdate) <br> { <br> seldate=maxdate-1; <br> } <br> }<br> reAppendSelect(obj,1,maxdate,seldate 1); <br>} <br>function SetCurrentYear(selecter,currYear) <br>{ <br> if(currYear==null){ <br> currYear=Math.round(selecter.options[selecter.selectedIndex].value); <br> } <br> reAppendSelect(selecter,currYear-10,currYear 10,currYear); <br>} <br>function reAppendSelect(selecter,startIndex,endIndex,selIndex) <br>{ <br> while(selecter.options.length>0) <br> { <br> selecter.removeChild(selecter.options[selecter.options.length-1]); <br> } <br> for(i=startIndex;i<=endIndex;i ) <BR> { <BR> var op=new Option(i,i); <BR> selecter.options.add(op); <BR> op.selected=(selIndex==i); <BR> } <BR>} <BR>function al(obj,lissener,func){ <BR> if(agt.indexOf('firefox')!=-1){ <BR> obj.addEventListener(lissener,function(){eval(func);},false); <BR> }else{ <BR> obj.attachEvent('on' lissener,function(){eval(func);}); <BR> } <BR>} <BR></script>
精简只有年:
日期控件 <script> <br><br><br><br>var agt = navigator.userAgent.toLowerCase(); <br>var OldTextBox; <br>function DateSeter(obj){ <br> var parent=obj.parentNode; <br><br> var selYear=document.createElement('SELECT'); <br> selYear.id='LoftyYear'; <br> parent.insertBefore(selYear,obj); <br>/* <br> var btnSubmit=document.createElement('BUTTON'); <br> btnSubmit.style.width='32px'; <br> parent.insertBefore(btnSubmit,obj); <br> btnSubmit.id='LoftyBtn'; <br><br> btnSubmit.textContent='OK'; <br> btnSubmit.value='OK'; <br> al(btnSubmit,'click','Restore()'); <br>*/ <br> OldTextBox=obj; <br> parent.removeChild(obj); <br> var defaultValue = obj.value; <br> var now=new Date(); <br> var cYear=now.getFullYear(); <br> SetCurrentYear(selYear,cYear,defaultValue); <br> al(selYear,'change','Restore(obj)'); <br>} <br>function Restore() <br>{ <br>OldTextBox.value = arguments[0].value; <br>var yy=document.getElementById('LoftyYear'); <br>var parent=yy.parentNode; <br>parent.insertBefore(OldTextBox,yy); <br>parent.removeChild(yy); <br>/* <br> var yy=document.getElementById('LoftyYear'); <br> var btn=document.getElementById('LoftyBtn'); <br> var time=yy.options[yy.selectedIndex].value; <br> OldTextBox.value=time; <br> var parent=yy.parentNode; <br> parent.insertBefore(OldTextBox,yy); <br> parent.removeChild(yy); <br> parent.removeChild(btn); <br>*/ <br>} <br>function SetCurrentYear(selecter,currYear) <br>{ <br> if(currYear==null){ <br> currYear=Math.round(selecter.options[selecter.selectedIndex].value); <br> } <br> var dv = arguments[2]; <br> reAppendSelect(selecter,1901,2001,currYear,dv); <br>} <br>function reAppendSelect(selecter,startIndex,endIndex,selIndex) <br>{ <br> while(selecter.options.length>0) <br> { <br> selecter.removeChild(selecter.options[selecter.options.length-1]); <br> } <br> for(i=startIndex;i<=endIndex;i ) <BR> { <BR> var op=new Option(i,i); <BR> selecter.options.add(op); <BR> if(arguments[4]!=""){ <BR> if(i==arguments[4]) <BR> op.selected=true; <BR> }else{ <BR> if (i==endIndex) <BR> op.selected=true; <BR> } <BR> } <br><br>} <BR>function al(obj,lissener,func){ <BR> if(agt.indexOf('firefox')!=-1){ <BR> obj.addEventListener(lissener,function(){eval(func);},false); <BR> }else{ <BR> obj.attachEvent('on' lissener,function(){eval(func);}); <BR> } <BR>} <br><br><BR></script>
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn