欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JS时间选择器 兼容IE6,7,8,9

程序员文章站 2023-12-11 23:30:10
在线演示: 复制代码 代码如下: js日期选择器并自动加入到输入框中</title>...</div> <div class="content"> 在线演示: <br><br><div class="codetitle"> <span><a style="cursor: pointer" data="53631" class="copybut" id="copybut53631" onclick="docopy('code53631')" target="_blank" rel="nofollow" href="/default/index/url?u=aHR0cHM6Ly93d3cuMTBxaWFud2FuLmNvbQ=="><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code53631"> <br><html> <br><head> <br><title>js日期选择器并自动加入到输入框中</title> <br><meta http-equiv="content-type" content="text/html;charset=gb2312"> <br><script type="text/javascript"> <br>var gmonths=new array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); <br>var weekday=new array("日","一","二","三","四","五","六"); <br>var strtoday="今天"; <br>var stryear="年"; <br>var strmonth="月"; <br>var strday="日"; <br>var splitchar="-"; <br>var startyear=2000; <br>var endyear=2050; <br>var daytdheight=12; <br>var daytdtextsize=12; <br>var gcnotcurmonth="#e0e0e0"; <br>var gcrestday="#ff0000"; <br>var gcworkday="#444444"; <br>var gcmouseover="#79d0ff"; <br>var gcmouseout="#f4f4f4"; <br>var gctoday="#444444"; <br>var gctodaymouseover="#6699ff"; <br>var gctodaymouseout="#79d0ff"; <br>var gdctrl=new object(); <br>var goselecttag=new array(); <br>var gdcurdate=new date(); <br>var giyear=gdcurdate.getfullyear(); <br>var gimonth=gdcurdate.getmonth()+1; <br>var giday=gdcurdate.getdate(); <br>function $(){var elements=new array();for(var i=0;i<arguments.length;i++) {var element=arguments[i];if(typeof(arguments[i])=='string'){element=document.getelementbyid(arguments[i]);}if(arguments.length==1){return element;}elements.push(element);}return elements;} <br>array.prototype.push=function(){var startlength=this.length;for(var i=0;i<arguments.length;i++){this[startlength+i]=arguments[i];}return this.length;} <br>string.prototype.hextodec=function(){return parseint(this,16);} <br>string.prototype.cleanblank=function(){return this.isempty()?"":this.replace(/\s/g,"");} <br>function checkcolor(){var color_tmp=(arguments[0]+"").replace(/\s/g,"").touppercase();var model_tmp1=arguments[1].touppercase();var model_tmp2="rgb("+arguments[1].substring(1,3).hextodec()+","+arguments[1].substring(1,3).hextodec()+","+arguments[1].substring(5).hextodec()+")";model_tmp2=model_tmp2.touppercase();if(color_tmp==model_tmp1 ||color_tmp==model_tmp2){return true;}return false;} <br>function $v(){return $(arguments[0]).value;} <br>function fpopcalendar(evt,popctrl,datectrl){evt.cancelbubble=true;gdctrl=datectrl;fsetyearmon(giyear,gimonth);var point=fgetxy(popctrl);with($("calendardiv").style){left=point.x+"px";top=(point.y+popctrl.offsetheight+1)+"px";visibility='visible';zindex='99';position='absolute';}$("calendardiv").focus();} <br>function fsetdate(iyear,imonth,iday){var imonthnew=new string(imonth);var idaynew=new string(iday);if(imonthnew.length<2){imonthnew="0"+imonthnew;}if(idaynew.length<2){idaynew="0"+idaynew;}gdctrl.value=iyear+splitchar+imonthnew+splitchar+idaynew;fhidecalendar();} <br>function fhidecalendar(){$("calendardiv").style.visibility="hidden";for(var i=0;i<goselecttag.length;i++){goselecttag[i].style.visibility="visible";}goselecttag.length=0;} <br>function fsetselected(){var ioffset=0;var iyear=parseint($("tbselyear").value);var imonth=parseint($("tbselmonth").value);var acell=$("celltext"+arguments[0]);acell.bgcolor=gcmouseout;with(acell){var iday=parseint(innerhtml);if(checkcolor(style.color,gcnotcurmonth)){ioffset=(innerhtml>10)?-1:1;}imonth+=ioffset;if(imonth<1){iyear--;imonth=12;}else if(imonth>12){iyear++;imonth=1;}}fsetdate(iyear,imonth,iday);} <br>function point(ix,iy){this.x=ix;this.y=iy;} <br>function fbuildcal(iyear,imonth){var amonth=new array();for(var i=1;i<7;i++){amonth[i]=new array(i);}var dcaldate=new date(iyear,imonth-1,1);var idayoffirst=dcaldate.getday();var idaysinmonth=new date(iyear,imonth,0).getdate();var ioffsetlast=new date(iyear,imonth-1,0).getdate()-idayoffirst+1;var idate=1;var inext=1;for(var d=0;d<7;d++){amonth[1][d]=(d<idayoffirst)?(ioffsetlast+d)*(-1):idate++;}for(var w=2;w<7;w++){for(var d=0;d<7;d++){amonth[w][d]=(idate<=idaysinmonth)?idate++:(inext++)*(-1);}}return amonth;} <br>function fdrawcal(iyear,imonth,icellheight,idatetextsize){var colortd=" bgcolor='"+gcmouseout+"' bordercolor='"+gcmouseout+"'";var styletd=" valign='middle' align='center' style='height:"+icellheight+"px;font-weight:bolder;font-size:"+idatetextsize+"px;";var datecal="";datecal+="<tr>";for(var i=0;i<7;i++){datecal+="<td"+colortd+styletd+"color:#990099'>"+weekday[i]+"</td>";}datecal+="</tr>";for(var w=1;w<7;w++){datecal+="<tr>";for(var d=0;d<7;d++){var tmpid=w+""+d;datecal+="<td"+styletd+"cursor:pointer;' onclick='fsetselected("+tmpid+")'>";datecal+="<span id='celltext"+tmpid+"'></span>";datecal+="</td>";}datecal+="</tr>";}return datecal;} <br>function fupdatecal(iyear,imonth){var mymonth=fbuildcal(iyear,imonth);var i=0;for(var w=1;w<7;w++){for(var d=0;d<7;d++){with($("celltext"+w+""+d)){parentnode.bgcolor=gcmouseout;parentnode.bordercolor=gcmouseout;parentnode.onmouseover=function(){this.bgcolor=gcmouseover;};parentnode.onmouseout=function(){this.bgcolor=gcmouseout;};if(mymonth[w][d]<0){style.color=gcnotcurmonth;innerhtml=math.abs(mymonth[w][d]);}else{style.color=((d==0)||(d==6))?gcrestday:gcworkday;innerhtml=mymonth[w][d];if(iyear==giyear && imonth==gimonth && mymonth[w][d]==giday){style.color=gctoday;parentnode.bgcolor=gctodaymouseout;parentnode.onmouseover=function(){this.bgcolor=gctodaymouseover;};parentnode.onmouseout=function(){this.bgcolor=gctodaymouseout;};}}}}}} <br>function fsetyearmon(iyear,imon){$("tbselmonth").options[imon-1].selected=true;for(var i=0;i<$("tbselyear").length;i++){if($("tbselyear").options[i].value==iyear){$("tbselyear").options[i].selected=true;}}fupdatecal(iyear,imon);} <br>function fprevmonth(){var imon=$("tbselmonth").value;var iyear=$("tbselyear").value;if(--imon<1){imon=12;iyear--;}fsetyearmon(iyear,imon);} <br>function fnextmonth(){var imon=$("tbselmonth").value;var iyear=$("tbselyear").value;if(++imon>12){imon=1;iyear++;}fsetyearmon(iyear,imon);} <br>function fgetxy(atag){var otmp=atag;var pt=new point(0,0);do{pt.x+=otmp.offsetleft;pt.y+=otmp.offsettop;otmp=otmp.offsetparent;}while(otmp.tagname.touppercase()!="body");return pt;} <br>function getdatediv(){var noselectforie="";var noselectforfirefox="";if(document.all){noselectforie="onselectstart='return false;'";}else{noselectforfirefox="-moz-user-select:none;";}var datediv="";datediv+="<div id='calendardiv' onclick='event.cancelbubble=true' "+noselectforie+" style='"+noselectforfirefox+"position:absolute;z-index:99;visibility:hidden;border:1px solid #999999;'>";datediv+="<table border='0' bgcolor='#e0e0e0' cellpadding='1' cellspacing='1' >";datediv+="<tr>";datediv+="<td><input type='button' id='prevmonth' value='<' style='height:20px;width:20px;font-weight:bolder;' onclick='fprevmonth()'>";datediv+="</td><td><select id='tbselyear' style='border:1px solid;' onchange='fupdatecal($v(\"tbselyear\"),$v(\"tbselmonth\"))'>";for(var i=startyear;i<endyear;i++){datediv+="<option value='"+i+"'>"+i+stryear+"</option>";}datediv+="</select></td><td>";datediv+="<select id='tbselmonth' style='border:1px solid;' onchange='fupdatecal($v(\"tbselyear\"),$v(\"tbselmonth\"))'>";for(var i=0;i<12;i++){datediv+="<option value='"+(i+1)+"'>"+gmonths[i]+"</option>";}datediv+="</select></td><td>";datediv+="<input type='button' id='nextmonth' value='>' style='height:20px;width:20px;font-weight:bolder;' onclick='fnextmonth()'>";datediv+="</td>";datediv+="</tr><tr>";datediv+="<td align='center' colspan='4'>";datediv+="<div style='background-color:#cccccc'><table width='100%' border='0' cellpadding='3' cellspacing='1'>";datediv+=fdrawcal(giyear,gimonth,daytdheight,daytdtextsize);datediv+="</table></div>";datediv+="</td>";datediv+="</tr><tr><td align='center' colspan='4' nowrap>";datediv+="<span style='cursor:pointer;font-weight:bolder;' onclick='fsetdate(giyear,gimonth,giday)' onmouseover='this.style.color=\""+gcmouseover+"\"' onmouseout='this.style.color=\"#000000\"'>"+strtoday+":"+giyear+stryear+gimonth+strmonth+giday+strday+"</span>";datediv+="</tr></tr>";datediv+="</table></div>";return datediv;} <br>with(document){onclick=fhidecalendar;write(getdatediv());} <br></script> <br></head> <br><body> <br><input type="text" style="border:1px solid #999;" onclick="fpopcalendar(event,this,this)" onfocus="this.select()" readonly="readonly" /> <br></body> <br></html> <br> </div> </div> <div class="info-pre-next"> <p> 上一篇: <a href="/article/.html"> </a> </p> <p> 下一篇: <a href="/article/.html"> </a> </p> </div> <div class="wz_tuijian"> <p> 推荐阅读 </p> <ul> <li> <a href="/article/2246257.html" target="_blank" title="JS时间选择器 兼容IE6,7,8,9"> <h2> JS时间选择器 兼容IE6,7,8,9 </h2> </a> </li> <li> <a href="/article/2246184.html" target="_blank" title="js 获取子节点函数 (兼容FF与IE)"> <h2> js 获取子节点函数 (兼容FF与IE) </h2> </a> </li> <li> <a href="/article/2242109.html" target="_blank" title="兼容ie、firefox的图片自动缩放的css跟js代码分享"> <h2> 兼容ie、firefox的图片自动缩放的css跟js代码分享 </h2> </a> </li> <li> <a href="/article/2237411.html" target="_blank" title="随机显示个性签名的js代码(兼容ie,firefox)"> <h2> 随机显示个性签名的js代码(兼容ie,firefox) </h2> </a> </li> <li> <a href="/article/2215978.html" target="_blank" title="兼容IE、firefox以及chrome的js获取时间(getFullYear)"> <h2> 兼容IE、firefox以及chrome的js获取时间(getFullYear) </h2> </a> </li> <li> <a href="/article/2204487.html" target="_blank" title="IE8下CSS3选择器nth-child() 不兼容问题的解决方法"> <h2> IE8下CSS3选择器nth-child() 不兼容问题的解决方法 </h2> </a> </li> <li> <a href="/article/2188128.html" target="_blank" title="textbox 在光标位置插入字符功能的js实现(兼容ie,firefox)"> <h2> textbox 在光标位置插入字符功能的js实现(兼容ie,firefox) </h2> </a> </li> <li> <a href="/article/2187859.html" target="_blank" title="JS时间选择器 兼容IE6,7,8,9"> <h2> JS时间选择器 兼容IE6,7,8,9 </h2> </a> </li> <li> <a href="/article/2174842.html" target="_blank" title="js 获取子节点函数 (兼容FF与IE)"> <h2> js 获取子节点函数 (兼容FF与IE) </h2> </a> </li> <li> <a href="/article/2174693.html" target="_blank" title="兼容ie、firefox的图片自动缩放的css跟js代码分享"> <h2> 兼容ie、firefox的图片自动缩放的css跟js代码分享 </h2> </a> </li> </ul> </div> </article> </div> </main> <footer><div class="box"><div class="ft_nav"><div class="ft_about"><p>关于网站</p><ul><li><a href="/sitemap.xml" target="_blank" title="网站地图">网站地图</a></li><li><a href="/list/2/" title="最新程序员文章站">最新程序员文章站</a></li></ul></div><div class="ft_contact"><ul><li>本站所有数据收集于网络如有侵犯到您的权益,请联系我们进行下架处理。</li><li class="email_show"></li></ul></div></div><div class="copyright"><div class="cr_left"><p> 备案号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20058927号</a></p><p>© Copyright © 2020-2022 www.superweb999.com 程序员文章站. </p></div></div></div></footer> </body> </html>