计算机200多个js技巧代码梳理汇总.docx
200多个js技巧代码1 .文本框焦点问题OnBIUr:当失去输入焦点后产生该事件OnFoCUs:当输入获得焦点后,产生该文件OnChange:当文字值改变时,产生该事件OnSeIeCI:当文字加亮后,产生该文件<inputtype="1.ext"VaIUe="mm"onfocus=if(va1.ue="mm)va1.ue=''"onb1.ur=*if(VaIUe='')va1.ue='三f”点击时文字消失,失去焦点时文字再出现2 .网页按钮的特殊颜色<inputtype=buttonname=*Submi11"YaIUe="郭强"size=10CIaSS=S02Sty1.e="background-co1.or:rgb(235,207,22)”>3 .鼠标移入移出时颜色变化<inputtype="submit"Va1.Ue="找吧"name=*B1.*OnVoUSeoUt=this,sty1.e.Co1.Or="b1.ue"OnVOUSeOVer=this.sty1.e.Co1.or="red"C1.aSS="button”)<SE1.ECT><FORM><BODY><HTM1.>17,将按钮的特征改变<sty1.etype=z,textcss*><!.Sty1.e1.font-size:12px;background:#CCCCFF;border-width:thinthinthinthin;border-co1.or:ffCCCCFFKCCCCCffCCCCCC#CCCCFF).sty1.e2font-size:12px;font-weight:bo1.d:background:SCCFFCC;border-width:thinmediummediumthin:border-co1.or:#CCFF99#999999#999999#CCFF99><sty1.e>本例按钮的代码如下:<inputtype=*submit,name="Submit"Va1.Ue="提交"OnmOUSeoVer="this.cIassName=*S1.yIe2'"OnmOUSeou1.="Ihis.cIassName='sty1.e”CIaSS="s1.y1.e1.”18 .改变按钮的图片.<sty1.etype="textcss”><!.sty1.e3font-size:12px;background:ur1.(image/buttonbg1.gif);border:Opx;width:60px;height:22px.sty1.e4font-size:12px;font-weight:bo1.d:background:ur1.(imagebuttonbg2.gif);bo1.der:Opx0;width:60px;height:22px><sty1.e>本例的按钮代码如下:<inputtype="submit"name="Submi1.2"Va1.Ue="提交"onmouseover=*this.C1.assName=*sty1.e4,”OnmoUSeOUt="this.C1.assName='sty1.e3,“CIaSS="sty1.e3”>19 .打印页面<diVa1.ign="center"><aCIaSS=ConIenIhref="javascriptRoPrint()>”>打印本稿<aXdiv>20 .可以直接写htm1.语言document,wriIe("");21 .改变下拉框的颜色<se1.ectname="c1.assid”onChange=,changeIocation(document,myform,c1.assic!,optionsdocment.myform,c1.assid.Se1.ectedIndex.va1.ue)”SiZe=Tsty1.e=*co1.or:tt008080;font-size:9pt*>22 .转至目标UR1.window.Iocation=*httpguoguo*23 .传递该object的formUpdateSN(,guoqiang99267',this,form)functionUpdateSN(strVa1.e,StrForm)StrForm.SignInName.va1.ue=StrVa1.ue:returnfa1.se:24 .文字标签<1.abe1.for=z,A1.tName4*><inputname="A1.1.Name"type="RADI()”tabindex=*931,id="A1.tName4”>guoqiang99859<1.abe1>25 .Iayer2为组件的ID,可以控制组件是否可见document,a1.1.item('1.ayer2').sty1.e,disp1.ay="b1.ock”;document,a1.1.item(,1.ayer2,).sty1.e,disp1.ay="none"26 .将页面加入favorite中<script1anguage=javascript><!functionAddmeOur1.="htp:your.site.address"/你自己的主页地址tit1.e="YourSiteName*;/你自己的主页名称window,externa1.AddFavorite(ur1.,tit1.e);><script>/27 .过10秒自动关闭页面< scriptIangUage="JavaScript.”>functionc1.oseitOSetTimeout(*se1.f.c1.ose()”,10000)< /script>28 .可以比较字符的大小char=post.charAt(i);if(!(,O><=char&&char<=,9')29 .将字符转化为数字month=parseInt(char)30 .点击VaIUe非空的选项时转向指定连接<se1.ectonchange='i(this,va1.ue!="")window,open(this,va1.ue)C1.aSS="textinput”<optionSeIeCi.ed>主办单位</。P1.iOn<option><option><optionva1.ue=*.Cn/”>北京日报<oPtiC)n><optionVaIUe="http:WW”>北京晚报/option)<se1.ect>31 .改变背景颜色<tdwidth=*c1.ass=dpbgCo1.or=#FAFBFCOnmOUSeoVer="this.bgCo1.or='ttFFFFFF,OnmOUSeQUt="Ihis.bgCo1.or='UFFBFC'32 .改变文字输入框的背景颜色<sty1.e>.input2background-image:ur1.(,./images/inputbg.gif');font-size:12px;background-co1.or:ffDODBB:border-top-width:Ipx;border-right-width:Ipx;boi'der-bo11om-width:1.px;bordei1.eft-width:1.px<sty1.e><inputname=contenttype=textSiZe="47"C1.aSS="input2”max1.ength=-50*>33 .改变水平线的特征<hrSiZe="O"noshadeco1.or="#CoCOCO”>34 .传递参数的方式<ahref="vote.asp?CurPage=8&id=3488w>8<a>35 .页内跳转< ahref=>1.<a>< ahref=Y2">2<a>< ahref=T3">3<a>< ahref=*4*>4<a>< ahref=5">5<a>< ahref=飞6">6<a>< ahref=*#7*>7</a><aname="1.">dfdf<a>< aname="2">dfdf</a>36 .两个按键一起按下if(event.Ctr1.Key&&window,event.keyCode=13)/37 .刷新页面javascript:this,1.ocation,re1.oad()/38 .将网页的按钮使能<SCRI1.ANGUAGE=*JavaScript*>functionhaha()for(vari=0;i<document.form1.e1.ements,1.ength;i+)if(document,fo11n1.e1.ementsi.name,indexf("bb")!=-1.)document,form1.e1.ementsi.disab1ed=!document.form1.e1.ementsi.disab1.ed;)<SCRIPT><B0DY><formname=form1.><INPUTTYPE="button"NAME=*aa"va1.ue=cindyonc1.ick=haha()><INPUTTYPE="button"NAME="bb"va1.ue=guoguo><INPUTTYPE="button"NAME=*bb"va1.ue=guoguo>39 .文字移动<marqueescro1.Iamount=3onmouseover=this.stopO;onnouseout=this.start();>40 .双击网页自动跑<SCRI1.ANGUAGE=*JavaScript*>Varcurrentpos,timer;functioninitia1.ize()timer=SetInterVa1("SCrO1.1.WindoW()”,1);)functionscOc1.earinterva1.(timer);)functionScro1.1.windowO(currentpos=document.body.scro1.1.Top:window.scro1.1.(O,+currentpos);if(currentpos!=document,body.scro1.1.Top)sc();document.OnmoUSedOwn=SCdocument,ondb1.c1.ick=initia1.ize<SCRIPT>/41 .后退<INPUTTYPE="button"onc1.ick=window.history.backOva1.ue=back><INPUTTYPE="bu1.1.on"one!ick=window.history,forward()va1.ue=forward>43 .刷新<INPUTTYPE="button"onc1.ick=documen1.1.ocation,re1.oad()va1.ue=re1.oad>44 .转向指定网页document.Iocation="h1.Ip:WW"