您正在使用IPV4(3.92.28.52)访问本站 您本次共访问本站 1 次
 用户名: 密 码: 验证码:     用QQ登录本站
首页 软件 编程 笑话 知识 公告 台风 日历 计算器 行情 简化版
文明驾车我带头,文明行路我带头,礼貌让座我带头      

[公益] 节省一分零钱 献出一份爱心 温暖世间真情       【腾讯云】爆款1核2G云服务器首年48元,还有iPad Pro、Bose耳机、京东卡等你来抽!      
虚位以待
2021年 冬至节 20
2021年 圣诞节 24
2022年 元 旦 31
2022年 春 节 62
 
  • 本类新增
    本类热门文章
    您现在的位置:首页 >> JS/CSS >> 内容
    Js日期选择并自动加入输入框
    内容摘要: htmlheadtitleJs日期选择器并自动加入到输入框中/titlemetahttp-equiv='content-Type'content='text/html;charset=gb2312'scripttype='text/javascript'vargMonths=newArray('一月','二月','三月','四月','五月','六月','七月......
    <html>

    <head>

    <title>Js日期选择器并自动加入到输入框中</title>

    <metahttp-equiv="content-Type"content="text/html;charset=gb2312">

    <scripttype="text/javascript">

    vargMonths=newArray("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");

    varWeekDay=newArray("日","一","二","三","四","五","六");

    varstrToday="今天";

    varstrYear="年";

    varstrMonth="月";

    varstrDay="日";

    varsplitChar="-";

    varstartYear=2000;

    varendYear=2050;

    vardayTdHeight=12;

    vardayTdTextSize=12;

    vargcNotCurMonth="#E0E0E0";

    vargcRestDay="#FF0000";

    vargcWorkDay="#444444";

    vargcMouseOver="#79D0FF";

    vargcMouseOut="#F4F4F4";

    vargcToday="#444444";

    vargcTodayMouseOver="#6699FF";

    vargcTodayMouseOut="#79D0FF";

    vargdCtrl=newObject();

    vargoSelectTag=newArray();

    vargdCurDate=newDate();

    vargiYear=gdCurDate.getFullYear();

    vargiMonth=gdCurDate.getMonth()+1;

    vargiDay=gdCurDate.getDate();

    function$(){varelements=newArray();for(vari=0;i<arguments.length;i++){varelement=arguments[i];if(typeof(arguments[i])=='string'){element=document.getElementById(arguments[i]);}if(arguments.length==1){returnelement;}elements.Push(element);}returnelements;}

    Array.prototype.Push=function(){varstartLength=this.length;for(vari=0;i<arguments.length;i++){this[startLength+i]=arguments[i];}returnthis.length;}

    String.prototype.HexToDec=function(){returnparseInt(this,16);}

    String.prototype.cleanBlank=function(){returnthis.isEmpty()?"":this.replace(/\s/g,"");}

    functioncheckColor(){varcolor_tmp=(arguments[0]+"").replace(/\s/g,"").toUpperCase();varmodel_tmp1=arguments[1].toUpperCase();varmodel_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){returntrue;}returnfalse;}

    function$V(){return$(arguments[0]).value;}

    functionfPopCalendar(evt,popCtrl,dateCtrl){evt.cancelBubble=true;gdCtrl=dateCtrl;fSetYearMon(giYear,giMonth);varpoint=fGetXY(popCtrl);with($("calendardiv").style){left=point.x+"px";top=(point.y+popCtrl.offsetHeight+1)+"px";visibility='visible';zindex='99';position='absolute';}$("calendardiv").focus();}

    functionfSetDate(iYear,iMonth,iDay){variMonthNew=newString(iMonth);variDayNew=newString(iDay);if(iMonthNew.length<2){iMonthNew="0"+iMonthNew;}if(iDayNew.length<2){iDayNew="0"+iDayNew;}gdCtrl.value=iYear+splitChar+iMonthNew+splitChar+iDayNew;fHideCalendar();}

    functionfHideCalendar(){$("calendardiv").style.visibility="hidden";for(vari=0;i<goSelectTag.length;i++){goSelectTag[i].style.visibility="visible";}goSelectTag.length=0;}

    functionfSetSelected(){variOffset=0;variYear=parseInt($("tbSelYear").value);variMonth=parseInt($("tbSelMonth").value);varaCell=$("cellText"+arguments[0]);aCell.bgColor=gcMouseOut;with(aCell){variDay=parseInt(innerHTML);if(checkColor(style.color,gcNotCurMonth)){iOffset=(innerHTML>10)?-1:1;}iMonth+=iOffset;if(iMonth<1){iYear--;iMonth=12;}elseif(iMonth>12){iYear++;iMonth=1;}}fSetDate(iYear,iMonth,iDay);}

    functionPoint(iX,iY){this.x=iX;this.y=iY;}

    functionfBuildCal(iYear,iMonth){varaMonth=newArray();for(vari=1;i<7;i++){aMonth[i]=newArray(i);}vardCalDate=newDate(iYear,iMonth-1,1);variDayOfFirst=dCalDate.getDay();variDaysInMonth=newDate(iYear,iMonth,0).getDate();variOffsetLast=newDate(iYear,iMonth-1,0).getDate()-iDayOfFirst+1;variDate=1;variNext=1;for(vard=0;d<7;d++){aMonth[1][d]=(d<iDayOfFirst)?(iOffsetLast+d)*(-1):iDate++;}for(varw=2;w<7;w++){for(vard=0;d<7;d++){aMonth[w][d]=(iDate<=iDaysInMonth)?iDate++:(iNext++)*(-1);}}returnaMonth;}

    functionfDrawCal(iYear,iMonth,iCellHeight,iDateTextSize){varcolorTD="bgcolor='"+gcMouseOut+"'bordercolor='"+gcMouseOut+"'";varstyleTD="valign='middle'align='center'style='height:"+iCellHeight+"px;font-weight:bolder;font-size:"+iDateTextSize+"px;";vardateCal="";dateCal+="<tr>";for(vari=0;i<7;i++){dateCal+="<td"+colorTD+styleTD+"color:#990099'>"+WeekDay[i]+"</td>";}dateCal+="</tr>";for(varw=1;w<7;w++){dateCal+="<tr>";for(vard=0;d<7;d++){vartmpid=w+""+d;dateCal+="<td"+styleTD+"cursor:pointer;'onclick='fSetSelected("+tmpid+")'>";dateCal+="<spanid='cellText"+tmpid+"'></span>";dateCal+="</td>";}dateCal+="</tr>";}returndateCal;}

    functionfUpdateCal(iYear,iMonth){varmyMonth=fBuildCal(iYear,iMonth);vari=0;for(varw=1;w<7;w++){for(vard=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;};}}}}}}

    functionfSetYearMon(iYear,iMon){$("tbSelMonth").options[iMon-1].selected=true;for(vari=0;i<$("tbSelYear").length;i++){if($("tbSelYear").options[i].value==iYear){$("tbSelYear").options[i].selected=true;}}fUpdateCal(iYear,iMon);}

    functionfPrevMonth(){variMon=$("tbSelMonth").value;variYear=$("tbSelYear").value;if(--iMon<1){iMon=12;iYear--;}fSetYearMon(iYear,iMon);}

    functionfNextMonth(){variMon=$("tbSelMonth").value;variYear=$("tbSelYear").value;if(++iMon>12){iMon=1;iYear++;}fSetYearMon(iYear,iMon);}

    functionfGetXY(aTag){varoTmp=aTag;varpt=newPoint(0,0);do{pt.x+=oTmp.offsetLeft;pt.y+=oTmp.offsetTop;oTmp=oTmp.offsetParent;}while(oTmp.tagName.toUpperCase()!="BODY");returnpt;}

    functiongetDateDiv(){varnoSelectForIE="";varnoSelectForFireFox="";if(document.all){noSelectForIE="onselectstart='returnfalse;'";}else{noSelectForFireFox="-moz-user-select:none;";}vardateDiv="";dateDiv+="<divid='calendardiv'onclick='event.cancelBubble=true'"+noSelectForIE+"style='"+noSelectForFireFox+"position:absolute;z-index:99;visibility:hidden;border:1pxsolid#999999;'>";dateDiv+="<tableborder='0'bgcolor='#E0E0E0'cellpadding='1'cellspacing='1'>";dateDiv+="<tr>";dateDiv+="<td><inputtype='button'id='PrevMonth'value='<'style='height:20px;width:20px;font-weight:bolder;'onclick='fPrevMonth()'>";dateDiv+="</td><td><selectid='tbSelYear'style='border:1pxsolid;'onchange='fUpdateCal($V(\"tbSelYear\"),$V(\"tbSelMonth\"))'>";for(vari=startYear;i<endYear;i++){dateDiv+="<optionvalue='"+i+"'>"+i+strYear+"</option>";}dateDiv+="</select></td><td>";dateDiv+="<selectid='tbSelMonth'style='border:1pxsolid;'onchange='fUpdateCal($V(\"tbSelYear\"),$V(\"tbSelMonth\"))'>";for(vari=0;i<12;i++){dateDiv+="<optionvalue='"+(i+1)+"'>"+gMonths[i]+"</option>";}dateDiv+="</select></td><td>";dateDiv+="<inputtype='button'id='NextMonth'value='>'style='height:20px;width:20px;font-weight:bolder;'onclick='fNextMonth()'>";dateDiv+="</td>";dateDiv+="</tr><tr>";dateDiv+="<tdalign='center'colspan='4'>";dateDiv+="<divstyle='background-color:#cccccc'><tablewidth='100%'border='0'cellpadding='3'cellspacing='1'>";dateDiv+=fDrawCal(giYear,giMonth,dayTdHeight,dayTdTextSize);dateDiv+="</table></div>";dateDiv+="</td>";dateDiv+="</tr><tr><tdalign='center'colspan='4'nowrap>";dateDiv+="<spanstyle='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>";returndateDiv;}

    with(document){onclick=fHideCalendar;write(getDateDiv());}

    </script>

    </head>

    <body>

    <inputtype="text"style="border:1pxsolid#999;"onclick="fPopCalendar(event,this,this)"onfocus="this.select()"readonly="readonly"/>

    </body>

    </html>

    版权声明:本内容来源于网络,如有侵犯您的版权,请联系站长,本站收到您的信息后将及时处理。
    上一篇:JavaScript判断表单输入框字符长度 下一篇:JavaScript获取系统字体
    发布日期:2021/10/20
    手机扫二维码直达本页
    发布时间:21:21:33
    点击:244
    录入:齐天大圣
    相关文章
    Baidu
    YiJiaCMS 6.0.9.10888 Build 21.11.30(MSSQL) 闽ICP备05000814号-1
    本空间由腾讯云(轻量应用服务器)提供,百度云加速提供加速防护
    ©2000-2021