javascript文档.doc_第1页
javascript文档.doc_第2页
javascript文档.doc_第3页
javascript文档.doc_第4页
javascript文档.doc_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

转贴js技巧事件源对象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自动刷新简单邮件快速转到位置obj.scrollIntoView(true)锚anchors网页传递参数location.search();可编辑obj.contenteditable=true执行菜单命令obj.execCommand双字节字符/x00-xff/汉字/u4e00-u9fa5/让英文字符串超出表格宽度自动换行word-wrap:break-word;word-break:break-all;透明背景获得style内容obj.style.cssTextHTML标签document.documentElement.innerHTML第一个style标签document.styleSheets0style标签里的第一个样式document.styleSheets0.rules0防止点击空链接时,页面往往重置到页首端。word上一网页源asp:request.servervariables(HTTP_REFERER)BLOCKEDSCRIPTdocument.referrer释放内存CollectGarbage();禁止右键document.oncontextmenu=function()returnfalse;禁止保存禁止选取禁止粘贴地址栏图标favicon.ico名字最好不变16*16的16色,放虚拟目录根目录下收藏栏图标查看源码关闭输入法自动全选ENTER键可以让光标移到下一个输入框文本框的默认值title换行obj.title=123 sdfs 获得时间所代表的微秒varn1=newDate(2004-10-10.replace(/-/g,/).getTime()窗口是否关闭win.closedcheckbox扁平获取选中内容document.selection.createRange().duplicate().text自动完成功能打开该功能关闭该功能窗口最大化无关闭按钮IEwindow.open(aa.htm,meizz,fullscreen=7);统一编码/解码alert(decodeURIComponent(encodeURIComponent(http:/你好.com?as=hehe)encodeURIComponent对:、/、;和?也编码表格行指示/各种尺寸s+=rn网页可见区域宽:+document.body.clientWidth;s+=rn网页可见区域高:+document.body.clientHeight;s+=rn网页可见区域高:+document.body.offsetWeight+(包括边线的宽);s+=rn网页可见区域高:+document.body.offsetHeight+(包括边线的宽);s+=rn网页正文全文宽:+document.body.scrollWidth;s+=rn网页正文全文高:+document.body.scrollHeight;s+=rn网页被卷去的高:+document.body.scrollTop;s+=rn网页被卷去的左:+document.body.scrollLeft;s+=rn网页正文部分上:+window.screenTop;s+=rn网页正文部分左:+window.screenLeft;s+=rn屏幕分辨率的高:+window.screen.height;s+=rn屏幕分辨率的宽:+window.screen.width;s+=rn屏幕可用工作区高度:+window.screen.availHeight;s+=rn屏幕可用工作区宽度:+window.screen.availWidth;/过滤数字=48&event.keyCode=57|(this.value.indexOf(.)/特殊用途/不缓存/正则匹配匹配中文字符的正则表达式:u4e00-u9fa5匹配双字节字符(包括汉字在内):x00-xff匹配空行的正则表达式:ns|*r匹配HTML标记的正则表达式:/.*|/匹配首尾空格的正则表达式:(s*)|(s*$)(像vbscript那样的trim函数)匹配Email地址的正则表达式:w+(-+.w+)*w+(-.w+)*.w+(-.w+)*匹配网址URL的正则表达式:http:/(w-+.)+w-+(/w-./?%&=*)?以下是例子:利用正则表达式限制网页表单里的文本框输入内容:用正则表达式限制只能输入中文:onkeyup=value=value.replace(/u4E00-u9FA5/g,)onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/u4E00-u9FA5/g,)1.用正则表达式限制只能输入全角字符:onkeyup=value=value.replace(/uFF00-uFFFF/g,)onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/uFF00-uFFFF/g,)2.用正则表达式限制只能输入数字:onkeyup=value=value.replace(/d/g,)onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/d/g,)3.用正则表达式限制只能输入数字和英文:onkeyup=value=value.replace(/W/g,)onbeforepaste=clipboardData.setData(text,clipboardData.getData(text).replace(/d/g,)/消除图像工具栏or/无提示关闭functionClose()varua=navigator.userAgentvarie=navigator.appName=MicrosoftInternetExplorer?true:falseif(ie)varIEversion=parseFloat(ua.substring(ua.indexOf(MSIE)+5,ua.indexOf(;,ua.indexOf(MSIE)if(IEversion5.5)varstr=str+=;document.body.insertAdjacentHTML(beforeEnd,str);document.all.noTipClose.Click();elsewindow.opener=null;window.close();elsewindow.close()/取得控件得绝对位置(1)functiongetoffset(e)vart=e.offsetTop;varl=e.offsetLeft;while(e=e.offsetParent)t+=e.offsetTop;l+=e.offsetLeft;varrec=newArray(1);rec0=t;rec1=l;returnrec/获得控件的绝对位置(2)oRect=obj.getBoundingClientRect();oRect.leftoRect./最小化,最大化,关闭/光标停在文字最后functioncc()vare=event.srcElement;varr=e.createTextRange();r.moveStart(character,e.value.length);r.collapse(true);r.select();/页面进入和退出的特效进入页面推出页面这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23:0矩形缩小1矩形扩大2圆形缩小3圆形扩大4下到上刷新5上到下刷新6左到右刷新7右到左刷新8竖百叶窗9横百叶窗10错位横百叶窗11错位竖百叶窗12点扩散13左右到中间刷新14中间到左右刷新15中间到上下16上下到中间17右下到左上18右上到左下19左上到右下20左下到右上21横条22竖条23/网页是否被检索其中属性值有以下一些:属性值为all:文件将被检索,且页上链接可被查询;属性值为none:文件不被检索,而且不查询页上的链接;属性值为index:文件将被检索;属性值为follow:查询页上的链接;属性值为noindex:文件不检索,但可被查询链接;属性值为nofollow:/打印分页page1page2/设置打印functionwindow.onload()/-advancedfeaturesfactory.printing.SetMarginMeasure(2)/measuremarginsininchesfactory.printing.SetPageRange(false,1,3)/needpagesfrom1to3factory.printing.printer=HPDeskJet870Cfactory.printing.copies=2factory.printing.collate=truefactory.printing.paperSize=A4factory.printing.paperSource=Manualfeed/-basicfeaturesfactory.printing.header=居左显示&b居中显示&b居右显示页码,第&p页/共&P页factory.printing.footer=(自定义页脚)factory.printing.portrait=falsefactory.printing.leftMargin=0.75factory.printing.topMargin=1.5factory.printing.rightMargin=0.75factory.printing.bottomMargin=1.5functionPrint(frame)factory.printing.Print(true,frame)/printwithprompt具体使用手册,更多信息,点这里/自带的打印预览WebBrowser.ExecWB(1,1)打开Web.ExecWB(2,1)关闭现在所有的IE窗口,并打开一个新窗口Web.ExecWB(4,1)保存网页Web.ExecWB(6,1)打印Web.ExecWB(7,1)打印预览Web.ExecWB(8,1)打印页面设置Web.ExecWB(10,1)查看页面属性Web.ExecWB(15,1)好像是撤销,有待确认Web.ExecWB(17,1)全选Web.ExecWB(22,1)刷新Web.ExecWB(45,1)关闭窗体无提示.Noprintdisplay:none;.PageNextpage-break-after:always;/去掉打印时的页眉页脚varHKEY_Root,HKEY_Path,HKEY_Key;HKEY_Root=HKEY_CURRENT_USER;HKEY_Path=SoftwareMicrosoftInternetExplorerPageSetup;/设置网页打印的页眉页脚为空functionPageSetup_Null()tryvarWsh=newActiveXObject(WScript.Shell);HKEY_Key=header;Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,);HKEY_Key=footer;Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,);catch(e)/设置网页打印的页眉页脚为默认值functionPageSetup_Default()tryvarWsh=newActiveXObject(WScript.Shell);HKEY_Key=header;Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&w&b页码,&p/&P);HKEY_Key=footer;Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&u&b&d);catch(e)/浏览器验证functioncheckBrowser()this.ver=navigator.appVersionthis.dom=document.getElementById?1:0this.ie6=(this.ver.indexOf(MSIE6)-1&this.dom)?1:0;this.ie5=(this.ver.indexOf(MSIE5)-1&this.dom)?1:0;this.ie4=(document.all&!this.dom)?1:0;this.ns5=(this.dom&parseInt(this.ver)=5)?1:0;this.ns4=(document.layers&!this.dom)?1:0;this.mac=(this.ver.indexOf(Mac)-1)?1:0;this.ope=(navigator.userAgent.indexOf(Opera)-1);this.ie=(this.ie6|this.ie5|this.ie4)this.ns=(this.ns4|this.ns5)this.bw=(this.ie6|this.ie5|this.ie4|this.ns5|this.ns4|this.mac|this.ope)this.nbw=(!this.bw)returnthis;/计算内容宽和高functiontest(obj)varrange=obj.createTextRange();alert(内容区宽度:+range.boundingWidth+pxrn内容区高度:+range.boundingHeight+px);sdf/无模式的提示框functionmodelessAlert(Msg)window.showModelessDialog(BLOCKEDSCRIPTalert(+escape(Msg)+);window.close();,status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;);/屏蔽按键屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键!-/屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键/Author:meizz(梅花雨)2002-6-18functiondocument.oncontextmenu()event.returnValue=false;/屏蔽鼠标右键functionwindow.onhelp()returnfalse/屏蔽F1帮助functiondocument.onkeydown()if(window.event.altKey)&(window.event.keyCode=37)|/屏蔽Alt+方向键(window.event.keyCode=39)/屏蔽Alt+方向键alert(不准你使用ALT+方向键前进或后退网页!);event.returnValue=false;/*/*注:这还不是真正地屏蔽Alt+方向键,因为Alt+方向键弹出警告框时,按住Alt键不放,用鼠标点掉警告框,这种屏蔽方法就失效了。以后若有哪位高手有真正屏蔽Alt键的方法,请告知。*/if(event.keyCode=8)|/屏蔽退格删除键(event.keyCode=116)|/屏蔽F5刷新键(event.ctrlKey&event.keyCode=82)/Ctrl+Revent.keyCode=0;event.returnValue=false;if(event.keyCode=122)event.keyCode=0;event.returnValue=false;/屏蔽F11if(event.ctrlKey&event.keyCode=78)event.returnValue=false;/屏蔽Ctrl+nif(event.shiftKey&event.keyCode=121)event.returnValue=false;/屏蔽shift+F10if(window.event.srcElement.tagName=A&window.event.shiftKey)window.event.returnValue=false;/屏蔽shift加鼠标左键新开一网页if(window.event.altKey)&(window.event.keyCode=115)/屏蔽Alt+F4window.showModelessDialog(about:blank,dialogWidth:1px;dialogheight:1px);returnfalse;屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键/屏蔽打印mediaprint*display:none/移动的图层,拖动1.meizzvarObj;functionMouseDown(obj)Obj=obj;Obj.setCapture();Obj.l=event.x-Obj.style.pixelLeft;Obj.t=event.y-Obj.style.pixelTop;functionMouseMove()if(Obj!=null)Obj.style.left=event.x-Obj.l;Obj.style.top=event.y-Obj.t;functionMouseUp()if(Obj!=null)Obj.releaseCapture();Obj=null;2.wlecomevarorgMouseX;varorgMouseY;varorgObjX;varorgObjY;functiondoDrag()varmyObject=document.all.myDiv;varx=event.clientX;vary=event.clientY;myObject.style.left=x-(orgMouseX-orgObjX);myObject.style.top=y-(orgMouseY-orgObjY);functiondoMouseDown()orgMouseX=event.clientX;orgMouseY=event.clientY;orgObjX=parseInt(document.all.myDiv.style.left);orgObjY=parseInt(document.all.myDiv.style.top);/文档状态改变vardoc=window.framesf.document;functions()if(doc.readyState=complete)document.all.f.style.height=doc.body.scrollHeightdocument.all.f.style.width=doc.body.scrollWidthdoc.onreadyst

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论