JavaScript经典代码大全想索取更多相关资料请加qq:649085085或649086086目录partone代码一代码二代码三parttwo代码四代码五代码六OtherHTML经典笔记CSS笔记实用代码代码一1.oncontextmenu=window.event.returnvalue=false将彻底屏蔽鼠标右键tableborderoncontextmenu=return(false)tdno/table可用于Table2.bodyonselectstart=returnfalse取消选取、防止复制3.onpaste=returnfalse不准粘贴4.oncopy=returnfalse;oncut=returnfalse;防止复制5.linkrel=ShortcutIconhref=favicon.icoIE地址栏前换成自己的图标6.linkrel=Bookmarkhref=favicon.ico可以在收藏夹中显示出你的图标7.inputstyle=ime-mode:-Disabled关闭输入法8.永远都会带着框架scriptlanguage=javascript!--if(window==top)top.location.href=frames.htm;//frames.htm为框架网页//--/script9.防止被人frameSCRIPTLANGUAGE=javascript!--if(top.location!=self.location)top.location=self.location;//--/SCRIPT10.网页将不能被另存为noscriptiframesrc=*.html/iframe/noscript11.inputtype=buttonvalue=查看网页源代码onclick=window.location=`view-source:`+`;12.删除时确认ahref=`javascript:if(confirm(确实要删除吗?location=boos.asp?&areyou=删除&page=1`删除/a13.取得控件的绝对位置//javascriptscriptlanguage=javascriptfunctiongetIE(E){vart=e.offsetTop;varl=e.offsetLeft;while(e=e.offsetParent){t+=e.offsetTop;l+=e.offsetLeft;}alert(top=+t+/nleft=+l);}/script//VBScriptscriptlanguage=VBScript!--functiongetIE()dimt,l,a,bseta=document.all.img1t=document.all.img1.offsetTopl=document.all.img1.offsetLeftwhilea.tagNameBODYseta=a.offsetParentt=t+a.offsetTopl=l+a.offsetLeftwendmsgboxtop=&t&chr(13)&left=&l,64,得到控件的位置endfunction--/script14.光标是停在文本框文字的最后scriptlanguage=javascriptfunctioncc(){vare=event.srcElement;varr=e.createTextRange();r.moveStart(`character`,e.value.length);r.collapse(true);r.select();}/scriptinputtype=textname=text1value=123onfocus=cc()15.判断上一页的来源javascript:document.referrer16.最小化、最大化、关闭窗口objectid=hh1classid=clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11paramname=Commandvalue=Minimize/objectobjectid=hh2classid=clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11paramname=Commandvalue=Maximize/objectOBJECTid=hh3classid=clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11PARAMNAME=Commandvalue=Close/OBJECTinputtype=buttonvalue=最小化onclick=hh1.Click()inputtype=buttonvalue=最大化onclick=hh2.Click()inputtype=buttonvalue=关闭onclick=hh3.Click()本例适用于IE回到目录代码二17.屏蔽功能键Shift,Alt,Ctrlscriptfunctionlook(){if(event.shiftKey)alert(禁止按Shift键!;//可以换成ALTCTRL}document.onkeydown=look;/script18.网页不会被缓存METAHTTP-EQUIV=pragmaCONTENT=no-cacheMETAHTTP-EQUIV=Cache-ControlCONTENT=no-cache,must-revalidateMETAHTTP-EQUIV=expiresCONTENT=Wed,26Feb199708:21:57GMT或者METAHTTP-EQUIV=expiresCONTENT=019.怎样让表单没有凹凸感?inputtype=textstyle=border:1solid#000000或inputtype=textstyle=border-left:none;border-right:none;border-top:none;border-bottom:1solid#000000/textarea20.divspan&layer的区别?div(division)用来定义大段的页面元素,会产生转行span用来定义同一行内的元素,跟div的唯一区别是不产生转行layer是ns的标记,ie不支持,相当于div21.让弹出窗口总是在最上面:bodyonblur=this.focus();22.不要滚动条?让竖条没有:bodystyle=`overflow:-Scroll;overflow-y:hidden`/body让横条没有:bodystyle=`overflow:-Scroll;overflow-x:hidden`/body两个都去掉?更简单了bodyscroll=no/body23.怎样去掉图片链接点击后,图片周围的虚线?ahref=#onFocus=this.blur()imgsrc=logo.jpgborder=0/a24.电子邮件处理提交表单formname=form1method=postaction=mailto***@***.comenctype=text/plaininputtype=submit/form25.在打开的子窗口刷新父窗口的代码里如何写?window.opener.location.reload()26.如何设定打开页面的大小bodyonload=top.resizeTo(300,200);打开页面的位置bodyonload=top.moveBy(300,200);27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动stylebody{background-image:url(logo.gif);background-repeat:no-repeat;background-position:center;background-attachment:fixed}/style28.检查一段字符串是否全由数字组成scriptlanguage=javascript!--functioncheckNum(str){returnstr.match(//D/)==null}alert(checkNum(1232142141alert(checkNum(123214214a1//--/script29.获得一个窗口的大小document.body.clientWidth;document.body.clientHeight30.怎么判断是否是字符if(/[^/x00-/xff]/g.test(s))alert(含有汉字;elsealert(全是字符;31.TEXTAREA自适应文字行数的多少textarearows=1name=s1cols=27onpropertychange=this.style.posHeight=this.scrollHeight/textarea32.日期减去天数等于第二个日期scriptlanguage=javascriptfunctioncc(dd,dadd){//可以加上错误处理vara=newDate(dd)a=a.valueOf()a=a-dadd*24*60*60*1000a=newDate(A)alert(a.getFullYear()+年+(a.getMonth()+1)+月+a.getDate()+日}cc(12/23/2002,2)/script33.选择了哪一个RadioHTMLscriptlanguage=vbscriptfunctioncheckme()foreachobinradio1ifob.checkedthenwindow.alertob.valuenextendfunction/scriptBODYINPUTname=radio1type=radiovalue=stylecheckedstyleINPUTname=radio1type=radiovalue=barcodeBarcodeINPUTtype=buttonvalue=checkonclick=checkme()/BODY/HTML34.脚本永不出错SCRIPTLANGUAGE=javascript!--HidefunctionkillErrors(){returntrue;}window.onerror=killErrors;//--/SCRIPT35.ENTER键可以让光标移到下一个输入框inputonkeydown=if(event.keyCode==13)event.keyCode=936.检测某个网站的链接速度:把如下代码加入body区域中:scriptlanguage=javascripttim=1setInterval(tim++,100)b=1varautourl=newArray()autourl[1]=[2]=javacool.3322.netautourl[3]=[4]=[5]=(){document.write(formname=autoffor(vari=1;iautourl.length;i++)document.write(inputtype=textname=t