Heim > Web-Frontend > js-Tutorial > 不错的一个日期输入 动态_时间日期

不错的一个日期输入 动态_时间日期

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-05-16 19:24:32
Original
1559 Leute haben es durchsucht

复制代码 代码如下:

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



日期控件
<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>







精简只有年:
复制代码 代码如下:

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



日期控件
<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>






Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
Wo steht js?
Aus 1970-01-01 08:00:00
0
0
0
js-Dateicode nicht gefunden
Aus 1970-01-01 08:00:00
0
0
0
js addClass funktioniert nicht
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage