您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 冶金工业 > Javascript技巧集
javascript技巧集事件源对象event.srcElement.tagNameevent.srcElement.type捕获释放event.srcElement.setCapture();event.srcElement.releaseCapture();事件按键event.keyCodeevent.shiftKeyevent.altKeyevent.ctrlKey事件返回值event.returnValue鼠标位置event.xevent.y窗体活动元素document.activeElement绑定事件document.captureEvents(Event.KEYDOWN);访问窗体元素document.all(txt).focus();document.all(txt).select();窗体命令document.execCommand窗体COOKIEdocument.cookie菜单事件document.oncontextmenu创建元素document.createElement(SPAN);根据鼠标获得元素:document.elementFromPoint(event.x,event.y).tagName==TDdocument.elementFromPoint(event.x,event.y).appendChild(ms)窗体图片document.images[索引]窗体事件绑定document.onmousedown=scrollwindow;元素document.窗体.elements[索引]对象绑定事件document.all.xxx.detachEvent('onclick',a);插件数目navigator.plugins取变量类型typeof($js_libpath)==undefined下拉框下拉框.options[索引]下拉框.options.length查找对象document.getElementsByName(r1);document.getElementById(id);定时timer=setInterval('scrollwindow()',delay);clearInterval(timer);UNCODE编码escape(),unescape父对象obj.parentElement(dhtml)obj.parentNode(dom)交换表的行TableID.moveRow(2,1)替换CSSdocument.all.csss.href=a.css;并排显示display:inline隐藏焦点hidefocus=true根据宽度换行style=word-break:break-all自动刷新metaHTTP-EQUIV=refreshCONTENT=8;URL=简单邮件ahref=mailto:aaa@bbb.com?subject=ccc&body=xxxyyy快速转到位置obj.scrollIntoView(true)锚aname=firstahref=#firstanchors/a网页传递参数location.search();可编辑obj.contenteditable=true执行菜单命令obj.execCommand双字节字符/[^\x00-\xff]/汉字/[\u4e00-\u9fa5]/让英文字符串超出表格宽度自动换行word-wrap:break-word;word-break:break-all;透明背景IFRAMEsrc=1.htmwidth=300height=180allowtransparency/iframe获得style内容obj.style.cssTextHTML标签document.documentElement.innerHTML第一个style标签document.styleSheets[0]style标签里的第一个样式document.styleSheets[0].rules[0]防止点击空链接时,页面往往重置到页首端。ahref=javascript:function()word/a上一网页源asp:request.servervariables(HTTP_REFERER)javascript:document.referrer释放内存CollectGarbage();禁止右键document.oncontextmenu=function(){returnfalse;}禁止保存noscriptiframesrc=*.htm/iframe/noscript禁止选取bodyoncontextmenu=returnfalseondragstart=returnfalseonselectstart=returnfalseonselect=document.selection.empty()oncopy=document.selection.empty()onbeforecopy=returnfalseonmouseup=document.selection.empty()禁止粘贴inputtype=textonpaste=returnfalse地址栏图标linkrel=ShortcutIconhref=favicon.icofavicon.ico名字最好不变16*16的16色,放虚拟目录根目录下收藏栏图标linkrel=Bookmarkhref=favicon.ico查看源码inputtype=buttonvalue=查看网页源代码onclick=window.location='view-source:'+'关闭输入法inputstyle=ime-mode:disabled自动全选inputtype=textname=text1value=123onfocus=this.select()ENTER键可以让光标移到下一个输入框inputonkeydown=if(event.keyCode==13)event.keyCode=9文本框的默认值inputtype=textvalue=123onfocus=alert(this.defaultValue)title换行obj.title=123 sdfs 获得时间所代表的微秒varn1=newDate(2004-10-10.replace(/-/g,\/)).getTime()窗口是否关闭win.closedcheckbox扁平inputtype=checkboxstyle=position:absolute;clip:rect(5px15px15px5px)br获取选中内容document.selection.createRange().duplicate().text自动完成功能inputtype=textautocomplete=on打开该功能inputtype=textautocomplete=off关闭该功能窗口最大化bodyonload=window.resizeTo(window.screen.width-4,window.screen.height-50);window.moveTo(-4,-4)无关闭按钮IEwindow.open(aa.htm,meizz,fullscreen=7);统一编码/解码alert(decodeURIComponent(encodeURIComponent(http://你好.com?as=hehe)))encodeURIComponent对:、/、;和?也编码表格行指示tronmouseover=this.bgColor='#f0f0f0'onmouseout=this.bgColor='#ffffff'//各种尺寸s+=\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;//过滤数字inputtype=textonkeypress=returnevent.keyCode=48&&event.keyCode=57||(this.value.indexOf('.')0?event.keyCode==46:false)onpaste=return!clipboardData.getData('text').match(/\D/)ondragenter=returnfalse//特殊用途inputtype=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.external.addChannel(')inputtype=buttonvalue=加入到频道onclick=window.external.showBrowserUI('PrivacySettings',null)//不缓存METAHTTP-EQUIV=pragmaCONTENT=no-cacheMETAHTTP-EQUIV=Cache-ControlCONTENT=no-cache,must-revalidateMETAHTTP-EQUIV=expiresCONTENT=0//正则匹配匹配中文字符的正则表达式:[\u4e00-\u9
本文标题:Javascript技巧集
链接地址:https://www.777doc.com/doc-5359821 .html