您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 市场营销 > 常用的一些javascript小技巧
常用的一些javascript小技巧事件源对象Quoteevent.srcElement.tagNameevent.srcElement.type捕获释放Quoteevent.srcElement.setCapture();event.srcElement.releaseCapture();事件按键Quoteevent.keyCodeevent.shiftKeyevent.altKeyevent.ctrlKey事件返回值Quoteevent.returnValue鼠标位置Quoteevent.xevent.y窗体活动元素Quotedocument.activeElement绑定事件Quotedocument.captureEvents(Event.KEYDOWN);访问窗体元素Quotedocument.all(txt).focus();document.all(txt).select();窗体命令Quotedocument.execCommand窗体COOKIEQuotedocument.cookie菜单事件Quotedocument.oncontextmenu创建元素Quotedocument.createElement(SPAN);根据鼠标获得元素:Quotedocument.elementFromPoint(event.x,event.y).tagName==TDdocument.elementFromPoint(event.x,event.y).appendChild(ms)窗体图片Quotedocument.images[索引]窗体事件绑定Quotedocument.onmousedown=scrollwindow;元素Quotedocument.窗体.elements[索引]对象绑定事件Quotedocument.all.xxx.detachEvent('onclick',a);插件数目Quotenavigator.plugins取变量类型Quotetypeof($js_libpath)==undefined下拉框Quote下拉框.options[索引]下拉框.options.length查找对象Quotedocument.getElementsByName(r1);document.getElementById(id);定时Quotetimer=setInterval('scrollwindow()',delay);clearInterval(timer);UNCODE编码Quoteescape(),unescape父对象Quoteobj.parentElement(dhtml)obj.parentNode(dom)交换表的行QuoteTableID.moveRow(2,1)替换CSSQuotedocument.all.csss.href=a.css;并排显示Quotedisplay:inline隐藏焦点Quotehidefocus=true根据宽度换行Quotestyle=word-break:break-all自动刷新QuotemetaHTTP-EQUIV=refreshCONTENT=8;URL==mailto:aaa@bbb.com?subject=ccc&body=xxxyyy快速转到位置Quoteobj.scrollIntoView(true)锚Quoteaname=firstahref=#firstanchors/a网页传递参数Quotelocation.search();可编辑Quoteobj.contenteditable=true执行菜单命令Quoteobj.execCommand双字节字符Quote/[^\x00-\xff]/汉字Quote/[\u4e00-\u9fa5]/让英文字符串超出表格宽度自动换行Quoteword-wrap:break-word;word-break:break-all;透明背景QuoteIFRAMEsrc=1.htmwidth=300height=180allowtransparency/iframe获得style内容Quoteobj.style.cssTextHTML标签Quotedocument.documentElement.innerHTML第一个style标签Quotedocument.styleSheets[0]style标签里的第一个样式Quotedocument.styleSheets[0].rules[0]防止点击空链接时,页面往往重置到页首端。Quoteahref=javascript:function()word/aQuote上一网页源Quoteasp:request.servervariables(HTTP_REFERER)javascript:document.referrer释放内存QuoteCollectGarbage();禁止右键Quotedocument.oncontextmenu=function(){returnfalse;}禁止保存Quotenoscriptiframesrc=*.htm/iframe/noscript禁止选取Quotebodyoncontextmenu=returnfalseondragstart=returnfalseonselectstart=returnfalseonselect=document.selection.empty()oncopy=document.selection.empty()onbeforecopy=returnfalseonmouseup=document.selection.empty()禁止粘贴Quoteinputtype=textonpaste=returnfalse地址栏图标Quotelinkrel=ShortcutIconhref=favicon.icofavicon.ico名字最好不变16*16的16色,放虚拟目录根目录下收藏栏图标Quotelinkrel=Bookmarkhref=favicon.ico查看源码Quoteinputtype=buttonvalue=查看网页源代码onclick=window.location='view-source:'+'关闭输入法Quoteinputstyle=ime-mode:disabled自动全选Quoteinputtype=textname=text1value=123onfocus=this.select()ENTER键可以让光标移到下一个输入框Quoteinputonkeydown=if(event.keyCode==13)event.keyCode=9文本框的默认值Quoteinputtype=textvalue=123onfocus=alert(this.defaultValue)title换行Quoteobj.title=123 sdfs 获得时间所代表的微秒Quotevarn1=newDate(2004-10-10.replace(/-/g,\/)).getTime()窗口是否关闭Quotewin.closedcheckbox扁平Quoteinputtype=checkboxstyle=position:absolute;clip:rect(5px15px15px5px)获取选中内容Quotedocument.selection.createRange().duplicate().text自动完成功能Quoteinputtype=textautocomplete=on打开该功能inputtype=textautocomplete=off关闭该功能窗口最大化Quotebodyonload=window.resizeTo(window.screen.width-4,window.screen.height-50);window.moveTo(-4,-4)无关闭按钮IEQuotewindow.open(aa.htm,meizz,fullscreen=7);统一编码/解码Quotealert(decodeURIComponent(encodeURIComponent(http://你好.com?as=hehe)))encodeURIComponent对:、/、;和?也编码表格行指示Quotetronmouseover=this.bgColor='#f0f0f0'onmouseout=this.bgColor='#ffffff'//各种尺寸Quotes+=\r\n网页可见区域宽:+document.body.clientWidth;s+=\r\n网页可见区域高:+document.body.clientHeight;s+=\r\n网页可见区域高:+document.body.offsetWeight+(包括边线的宽);s+=\r\n网页可见区域高:+document.body.offsetHeight+(包括边线的宽);s+=\r\n网页正文全文宽:+document.body.scrollWidth;s+=\r\n网页正文全文高:+document.body.scrollHeight;s+=\r\n网页被卷去的高:+document.body.scrollTop;s+=\r\n网页被卷去的左:+document.body.scrollLeft;s+=\r\n网页正文部分上:+window.screenTop;s+=\r\n网页正文部分左:+window.screenLeft;s+=\r\n屏幕分辨率的高:+window.screen.height;s+=\r\n屏幕分辨率的宽:+window.screen.width;s+=\r\n屏幕可用工作区高度:+window.screen.availHeight;s+=\r\n屏幕可用工作区宽度:+window.screen.availWidth;过滤数字Quoteinputtype=textonkeypress=returnevent.keyCode=48&&event.keyCode=57||(this.value.indexOf('.')0?event.keyCode==46:false)onpaste=return!clipboardData.getData('text').match(/\D/)ondragenter=returnfalse特殊用途Quoteinputtype=buttonvalue=导入收藏夹onclick=window.external.ImportExportFavorites(true,');inputtype=buttonvalue=导出收藏夹onclick=window.external.ImportExportFavorites(false,');inputtype=buttonvalue=整理收藏夹onclick=window.external.ShowBrowserUI('OrganizeFavorites',null)inputtype=buttonvalue=语言设置onclick=window.external.ShowBrowserUI('LanguageDialog',null)inputtype=buttonvalue=加入收藏夹onclick=window.external.AddFavorite(')inputtype=buttonvalue=加入到频道onclick=window
本文标题:常用的一些javascript小技巧
链接地址:https://www.777doc.com/doc-5451868 .html