javascript 常用事件.doc_第1页
javascript 常用事件.doc_第2页
javascript 常用事件.doc_第3页
javascript 常用事件.doc_第4页
javascript 常用事件.doc_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

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

文档简介

事件源對象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窗體COOKIEdocuments.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自動Reload簡單郵件快速轉到位置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)java script:document.referrer釋放內存CollectGarbage();禁止右鍵document.oncontextmenu = function() return false;禁止儲存禁止選取禁止貼上地址欄圖標favicon.ico 名字最好不變16*16的16色,放虛擬目錄根目錄下收藏欄圖標檢視原始碼關閉輸入法自動全選ENTER鍵可以讓游標移到下一個輸入框文字框的預設值title換行obj.title = 123 sdfs 獲得時間所代表的微秒var n1 = new Date(2004-10-10.replace(/-/g, /).getTime()視窗是否關閉win.closedcheckbox扁平獲取選取內容document.selection.createRange().duplicate().text自動完成功能打開該功能關閉該功能視窗最大化無關閉按鈕IEwindows.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無提示關閉function Close()var ua=navigator.userAgentvar ie=navigator.appName=Microsoft Internet Explorer?true:falseif(ie)var IEversion=parseFloat(ua.substring(ua.indexOf(MSIE )+5,ua.indexOf(;,ua.indexOf(MSIE )if(IEversion 5.5)var str = str += ;document.body.insertAdjacentHTML(beforeEnd, str);document.all.noTipClose.Click();elsewindows.opener =null;window.close();elsewindow.close()取得控件得絕對位置(1) function getoffset(e)var t=e.offsetTop;var l=e.offsetLeft;while(e=e.offsetParent)t+=e.offsetTop;l+=e.offsetLeft;var rec = new Array(1);rec0 = t;rec1 = l;return rec獲得控件的絕對位置(2) oRect = obj.getBoundingClientRect();oRect.leftoRect.最小化,最大化,關閉游標停在文字最後function cc()var e = event.srcElement;var r =e.createTextRange();r.moveStart(character,e.value.length);r.collapse(true);r.select();頁面進入和登出的特效進入頁面推出頁面這個是頁面被載入和調出時的一些特效。duration表示特效的持續時間,以秒為單位。transition表示使用哪種特效,取值為1-23:0 矩形縮小1 矩形擴大2 圓形縮小3 圓形擴大4 下到上Reload5 上到下Reload6 左到右Reload7 右到左Reload8 豎百葉窗9 橫百葉窗10 錯位橫百葉窗11 錯位豎百葉窗12 點擴散13 左右到中間Reload14 中間到左右Reload15 中間到上下16 上下到中間17 右下到左上18 右上到左下19 左上到右下20 左下到右上21 橫條22 豎條23網頁是否被檢索其中屬性值有以下一些:屬性值為all: 檔案將被檢索,且頁上連結可被查詢;屬性值為none: 檔案不被檢索,而且不查詢頁上的連結;屬性值為index: 檔案將被檢索;屬性值為follow: 查詢頁上的連結;屬性值為noindex: 檔案不檢索,但可被查詢連結;屬性值為nofollow:列印分頁page1page2設定列印function window.onload()/ - advanced featuresfactory.printing.SetMarginMeasure(2) / measure margins in inchesfactory.printing.SetPageRange(false, 1, 3) / need pages from 1 to 3factory.printing.printer = HP DeskJet 870Cfactory.printing.copies = 2factory.printing.collate = truefactory.printing.paperSize = A4factory.printing.paperSource = Manual feed/ - basic featuresfactory.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.5function Print(frame) factory.printing.Print(true, frame) / print with prompt實際使用手冊,更多訊息,點這裡自帶的列印預覽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) ReloadWeb.ExecWB(45,1) 關閉窗體無提示.Noprintdisplay:none;.PageNextpage-break-after: always; 去掉列印時的頁眉頁尾var HKEY_Root,HKEY_Path,HKEY_Key;HKEY_Root=HKEY_CURRENT_USER;HKEY_Path=SoftwareMicrosoftInternet ExplorerPageSetup;設定網頁列印的頁眉頁尾為空白function PageSetup_Null()tryvar Wsh=new ActiveXObject(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)設定網頁列印的頁眉頁尾為預設值function PageSetup_Default()tryvar Wsh=new ActiveXObject(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)瀏覽器驗證function checkBrowser()this.ver=navigator.appVersionthis.dom=document.getElementById?1:0this.ie6=(this.ver.indexOf(MSIE 6)-1 & this.dom)?1:0;this.ie5=(this.ver.indexOf(MSIE 5)-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)return this;計算內容寬和高function test(obj)var range = obj.createTextRange();alert(內容區寬度: + range.boundingWidth+ pxrn內容區高度: + range.boundingHeight + px);sdf無模式的提示框function modelessAlert(Msg)window.showModelessDialog(java script:alert(+escape(Msg)+);window.close();,status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;);阻斷按鍵阻斷滑鼠游標右鍵、Ctrl+N、Shift+F10、Alt+F4、F11、F5Reload、退格鍵!-/阻斷滑鼠游標右鍵、Ctrl+N、Shift+F10、F11、F5Reload、退格鍵/Author: meizz(梅花雨) 2002-6-18function document.oncontextmenu()event.returnvalue=false;/阻斷滑鼠游標右鍵function window.onhelp()return false /阻斷F1輔助function document.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 Reload鍵(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);return false;阻斷滑鼠游標右鍵、Ctrl+N、Shift+F10、Alt+F4、F11、F5Reload、退格鍵阻斷列印media print* display:none移動的圖層,拖動1.meizzvar Obj;function MouseDown(obj)Obj=obj;Obj.setCapture();Obj.l=event.x-Obj.style.pixelLeft;Obj.t=event.y-Obj.style.pixelTop;function MouseMove()if(Obj!=null)Obj.style.left = event.x-Obj.l;Obj.style.top = event.y-Obj.t;function MouseUp()if(Obj!=null)Obj.releaseCapture();Obj=null;2.wlecomevar orgMouseX;var orgMouseY;var orgObjX;var orgObjY;function doDrag()var myObject=document.all.myDiv;var x=event.clientX;var y=event.clientY;myObject.style.left=x-(orgMouseX-orgObjX);myObject.style.top=y-(orgMouseY-orgObjY);function doMouseDown()orgMouseX=event.clientX;orgMouseY=event.clientY;orgObjX=parseInt(document.all.myDiv.style.left);orgObjY=parseInt(document.all.myDiv.style.top);檔案狀態改變var doc=window.framesf.document;function s()if (doc.readyState=complete)document.all.f.style.height=doc.body.scrollHeightdocument.all.f.style.width=doc.body.scrollWidthdoc.onreadystatechange=sReload後不變的文字框.sHistory behavior:url(#default#savehistory);瀏覽剪貼板(1)拖拽瀏覽event.dataTransfer.setData(URL, oImage.src);sImageURL = event.dataTransfer.getData(URL)(2)一般瀏覽window.clipboardData.setData(Text,oSource.innerText);window.clipboardData.getData(Text);操作COOKIEfunction SetCookie(sName, svalue)documents.cookie = sName + = + escape(svalue) + ; ;function GetCookie(sName)var aCookie = documents.cookie.split(; );for (var i=0; i aCookie.length; i+)var aCrumb = aCookie.split(=);if (sName = aCrumb0)return unescape(aCrumb1);function DelCookie(sName)documents.cookie = sName + = + escape(svalue) + ; expires=Fri, 31 Dec 1999 23:59:59 GMT;setTimeout新增參數var _st = window.setTimeout;window.setTimeout = function(fRef, mDelay) if(typeof fRef = function)var argu = Atotype.slice.call(arguments,2);var f = (function() fRef.apply(null, argu); );return _st(f, mDelay);return _st(fRef,mDelay);function test(x)alert(x);window.setTimeout(test,1000,fason);自訂的apply,callFtotype.apply = function (obj,

温馨提示

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

评论

0/150

提交评论