常用的一些javascript小技巧

2006-01-13 00:39:25

事件源对象 [code]event.srcElement.tagName event.srcElement.type [/code] 捕获释放 [code]event.srcElement.setCapture(); event.srcElement.releaseCapture(); [/code] 事件按键 [code]event.keyCode event.shiftKey event.altKey event.ctrlKey [/code] 事件返回值 [code]event.returnValue [/code] 鼠标位置 event.x event.y 窗体活动元素 document.activeElement 绑定事件 [code]document.captureEvents(Event.KEYDOWN); [/code] 访问窗体元素 [code]document.all(&#34;txt&#34;).focus(); document.all(&#34;txt&#34;).sel&#101;ct(); [/code] 窗体命令 document.execCommand 窗体COOKIE document.cookie 菜单事件 document.oncontextmenu 创建元素 [code]document.cr&#101;ateElement(&#34;SPAN&#34;); [/code] 根据鼠标获得元素: [code]document.elementFromPoint(event.x,event.y).tagName==&#34;TD document.elementFromPoint(event.x,event.y).appendChild(ms) [/code] 窗体图片 document.images[索引] 窗体事件绑定 document.onmousedown=scrollwindow; 元素 document.窗体.elements[索引] 对象绑定事件 [code]document.all.xxx.detachEvent(&#39;onclick&#39;,a); [/code] 插件数目 navigator.plugins 取变量类型 [code]typeof($js_libpath) == &#34;undefined&#34; [/code] 下拉框 下拉框.options[索引] 下拉框.options.length 查找对象 [code]document.getElementsByName(&#34;r1&#34;); document.getElementById(id); [/code] 定时 [code]timer=setInterval(&#39;scrollwindow()&#39;,delay); clearInterval(timer); [/code] UNCODE编码 escape() ,unescape 父对象 [code]obj.parentElement(dhtml) obj.parentNode(dom) [/code] 交换表的行 [code]TableID.moveRow(2,1) [/code] 替换CSS document.all.csss.href = &#34;a.css&#34;; 并排显示 display:inline 隐藏焦点 hidefocus=true 根据宽度换行 style=&#34;word-break:break-all&#34; 自动刷新 <meta HTTP-EQUIV=&#34;refresh&#34; CONTENT=&#34;8;URL=http://c98.yeah.net&#34;> 简单邮件 <a href=&#34;mailto:aaa@bbb.com?subject=ccc&amp;body=xxxyyy&#34;> 快速转到位置 obj.scrollIntoView(true) 锚 <a name=&#34;first&#34;> <a href=&#34;#first&#34;>anchors</a> 网页传递参数 [code]location.search(); [/code] 可编辑 obj.contenteditable=true 执行菜单命令 obj.execCommand 双字节字符 /[^\x00-\xff]/ 汉字 /[\u4e00-\u9fa5]/ 让英文字符串超出表格宽度自动换行 word-wrap: break-word; word-break: break-all; 透明背景 <IFRAME src=&#34;1.htm&#34; width=300 height=180 allowtransparency></iframe> 获得style内容 obj.style.cssText HTML标签 document.documentElement.innerHTML 第一个style标签 document.styleSheets[0] style标签里的第一个样式 document.styleSheets[0].rules[0] 防止点击空链接时,页面往往重置到页首端。 [code]<a href=&#34;javascript:function()&#34;>word</a> 上一网页源 asp: request.servervariables(&#34;HTTP_REFERER&#34;) javascript: document.referrer [/code] 释放内存 [code]CollectGarbage(); [/code] 禁止右键 [code]document.oncontextmenu = function() { return false;} [/code] 禁止保存 [code]<noscript><iframe src=&#34;*.htm&#34;></iframe></noscript> [/code] 禁止选取 [code]<body oncontextmenu=&#34;return false&#34; ondragstart=&#34;return false&#34; onsel&#101;ctstart =&#34;return false&#34; onsel&#101;ct=&#34;document.sel&#101;ction.empty()&#34; oncopy=&#34;document.sel&#101;ction.empty()&#34; onbeforecopy=&#34;return false&#34;onmouseup=&#34;document.sel&#101;ction.empty()> [/code] 禁止粘贴 [code]<input type=text onpaste=&#34;return false&#34;> [/code] 地址栏图标 /favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下 [code]<link rel=&#34;Shortcut Icon&#34; href=&#34;favicon.ico&#34;> [/code] 收藏栏图标 [code]<link rel=&#34;Bookmark&#34; href=&#34;favicon.ico&#34;> [/code] 查看源码 [code]<input type=button value=查看网页源代码 onclick=&#34;window.location = &#39;view-source:&#39;+ &#39;http://www.csdn.net/&#39;&#34;> [/code] 关闭输入法 [code]<input style=&#34;ime-mode:disabled&#34;> [/code] 自动全选 [code]<input type=text name=text1 value=&#34;123&#34; onfocus=&#34;this.sel&#101;ct()&#34;> [/code] ENTER键可以让光标移到下一个输入框 [code]<input type=text value=&#34;123&#34; onfocus=&#34;alert(this.defaultValue)&#34;> [/code] title换行 [code]obj.title = &#34;123 sdfs &#34; [/code] 获得时间所代表的微秒 [code]var n1 = new Date(&#34;2004-10-10&#34;.replace(/-/g, &#34;\/&#34;)).getTime() [/code] 窗口是否关闭 [code]win.closed [/code] checkbox扁平 [code]<input type=checkbox style=&#34;position: absolute; clip:rect(5px 15px 15px 5px)&#34;> [/code] 获取选中内容 [code]document.sel&#101;ction.cr&#101;ateRange().duplicate().text [/code] 自动完成功能 [code]<input type=text autocomplete=on>打开该功能 <input type=text autocomplete=off>关闭该功能 [/code] 窗口最大化 [code]<body onload=&#34;window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)&#34;> [/code] 无关闭按钮IE [code]window.open(&#34;aa.htm&#34;, &#34;meizz&#34;, &#34;fullscreen=7&#34;); [/code] 统一编码/解码 [code]alert(decodeURIComponent(encodeURIComponent(&#34;http://你好.com?as= hehe&#34;))) encodeURIComponent对&#34;:&#34;、&#34;/&#34;、&#34;;&#34; 和 &#34;?&#34;也编码 [/code] 表格行指示 [code]<tr onmouseover=&#34;this.bgColor=&#39;#f0f0f0&#39;&#34; onmouseout=&#34;this.bgColor=&#39;#ffffff&#39;&#34;> [/code] //各种尺寸 [code]s += &#34;\r\n网页可见区域宽:&#34;+ document.body.clientWidth; s += &#34;\r\n网页可见区域高:&#34;+ document.body.clientHeight; s += &#34;\r\n网页可见区域高:&#34;+ document.body.offsetWeight +&#34; (包括边线的宽)&#34;; s += &#34;\r\n网页可见区域高:&#34;+ document.body.offsetHeight +&#34; (包括边线的宽)&#34;; s += &#34;\r\n网页正文全文宽:&#34;+ document.body.scrollWidth; s += &#34;\r\n网页正文全文高:&#34;+ document.body.scrollHeight; s += &#34;\r\n网页被卷去的高:&#34;+ document.body.scrollTop; s += &#34;\r\n网页被卷去的左:&#34;+ document.body.scrollLeft; s += &#34;\r\n网页正文部分上:&#34;+ window.screenTop; s += &#34;\r\n网页正文部分左:&#34;+ window.screenLeft; s += &#34;\r\n屏幕分辨率的高:&#34;+ window.screen.height; s += &#34;\r\n屏幕分辨率的宽:&#34;+ window.screen.width; s += &#34;\r\n屏幕可用工作区高度:&#34;+ window.screen.availHeight; s += &#34;\r\n屏幕可用工作区宽度:&#34;+ window.screen.availWidth; [/code] 过滤数字 [code]<input type=text onkeypress=&#34;return event.keyCode>=48&amp;&amp;event.keyCode<=57||(this.value.indexOf(&#39;.&#39;)<0?event.keyCode==46:false)&#34; onpaste=&#34;return !clipboardData.getData(&#39;text&#39;).match(/\D/)&#34; ondragenter=&#34;return false&#34;> [/code] 特殊用途 [code]<input type=button value=导入收藏夹 onclick=&#34;window.external.ImportExportFavorites(true,&#39;http://localhost&#39;);&#34;> <input type=button value=导出收藏夹 onclick=&#34;window.external.ImportExportFavorites(false,&#39;http://localhost&#39;);&#34;> <input type=button value=整理收藏夹 onclick=&#34;window.external.ShowBrowserUI(&#39;OrganizeFavorites&#39;, null)&#34;> <input type=button value=语言设置 onclick=&#34;window.external.ShowBrowserUI(&#39;LanguageDialog&#39;, null)&#34;> <input type=button value=加入收藏夹 onclick=&#34;window.external.AddFavorite(&#39;http://www.google.com/&#39;, &#39;google&#39;)&#34;> <input type=button value=加入到频道 onclick=&#34;window.external.addChannel(&#39;http://www.google.com/&#39;)&#34;> <input type=button value=加入到频道 onclick=&#34;window.external.showBrowserUI(&#39;PrivacySettings&#39;,null)&#34;> [/code] 不缓存 [code]<META HTTP-EQUIV=&#34;pragma&#34; CONTENT=&#34;no-cache&#34;> <META HTTP-EQUIV=&#34;Cache-Control&#34; CONTENT=&#34;no-cache, must-revalidate&#34;> <META HTTP-EQUIV=&#34;expires&#34; CONTENT=&#34;0&#34;> [/code] 正则匹配 [code]匹配中文字符的正则表达式: [\u4e00-\u9fa5] 匹配双字节字符(包括汉字在内):[^\x00-\xff] 匹配空行的正则表达式:\n[\s| ]*\r 匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/ 匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim函数) 匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)* 匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)? [/code] 以下是例子: 利用正则表达式限制网页表单里的文本框输入内容: [code]用正则表达式限制只能输入中文:onkeyup=&#34;value=value.replace(/[^\u4E00-\u9FA5]/g,&#39;&#39;)&#34; onbeforepaste=&#34;clipboardData.setData(&#39;text&#39;,clipboardData.getData(&#39;text&#39;).replace(/[^\u4E00-\u9FA5]/g,&#39;&#39;))&#34; 1.用正则表达式限制只能输入全角字符: onkeyup=&#34;value=value.replace(/[^\uFF00-\uFFFF]/g,&#39;&#39;)&#34; onbeforepaste=&#34;clipboardData.setData(&#39;text&#39;,clipboardData.getData(&#39;text&#39;).replace(/[^\uFF00-\uFFFF]/g,&#39;&#39;))&#34; 2.用正则表达式限制只能输入数字:onkeyup=&#34;value=value.replace(/[^\d]/g,&#39;&#39;) &#34;onbeforepaste=&#34;clipboardData.setData(&#39;text&#39;,clipboardData.getData(&#39;text&#39;).replace(/[^\d]/g,&#39;&#39;))&#34; 3.用正则表达式限制只能输入数字和英文:onkeyup=&#34;value=value.replace(/[\W]/g,&#39;&#39;) &#34;onbeforepaste=&#34;clipboardData.setData(&#39;text&#39;,clipboardData.getData(&#39;text&#39;).replace(/[^\d]/g,&#39;&#39;))&#34; [/code] 消除图像工具栏 [code]<IMG SRC=&#34;mypicture.jpg&#34; HEIGHT=&#34;100px&#34; WIDTH=&#34;100px&#34; GALLERYIMG=&#34;false&#34;> o&#114; <head> <meta http-equiv=&#34;imagetoolbar&#34; content=&#34;no&#34;> </head> [/code] 无提示关闭 [code]function Close() { var ua=navigator.userAgent var ie=navigator.appName==&#34;Microsoft Internet Explorer&#34;?true:false if(ie) { var IEversion=parseFloat(ua.substring(ua.indexOf(&#34;MSIE &#34;)+5,ua.indexOf(&#34;;&#34;,ua.indexOf(&#34;MSIE &#34;)))) if(IEversion< 5.5) { var str = &#39;<object id=noTipClose classid=&#34;clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11&#34;>&#39; str += &#39;<param name=&#34;Command&#34; value=&#34;Close&#34;></object>&#39;; document.body.ins&#101;rtAdjacentHTML(&#34;beforeEnd&#34;, str); document.all.noTipClose.Click(); } else { window.opener =null; window.close(); } } else { window.close() } } [/code] 取得控件得绝对位置(1) [code]<script language=&#34;javascript&#34;> 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); rec[0] = t; rec[1] = l; return rec } </script> [/code] 获得控件的绝对位置(2) [code]oRect = obj.getBoundingClientRect(); o&#114;ect.left o&#114;ect. [/code] 最小化,最大化,关闭 [code]<object id=min classid=&#34;clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11&#34;> <param name=&#34;Command&#34; value=&#34;Minimize&#34;></object> <object id=max classid=&#34;clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11&#34;> <param name=&#34;Command&#34; value=&#34;Maximize&#34;></object> <OBJECT id=close classid=&#34;clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11&#34;> <PARAM NAME=&#34;Command&#34; value=&#34;Close&#34;></OBJECT> <input type=button value=最小化 onclick=min.Click()> <input type=button value=最大化 onclick=max.Click()> <input type=button value=关闭 onclick=close.Click()> [/code] 光标停在文字最后 [code]<script language=&#34;javascript&#34;> function cc() { var e = event.srcElement; var r =e.cr&#101;ateTextRange(); r.moveStart(&#39;character&#39;,e.value.length); r.collapse(true); r.sel&#101;ct(); } </script> <input type=text name=text1 value=&#34;123&#34; onfocus=&#34;cc()&#34;> [/code] 页面进入和退出的特效 [code]进入页面<meta http-equiv=&#34;Page-Enter&#34; content=&#34;revealTrans(duration=x, transition=y)&#34;> 推出页面<meta http-equiv=&#34;Page-Exit&#34; content=&#34;revealTrans(duration=x, transition=y)&#34;> 这个是页面被载入和调出时的一些特效。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 [/code] 网页是否被检索 [code]<meta name=&#34;ROBOTS&#34; content=&#34;属性值&#34;>   其中属性值有以下一些:   属性值为&#34;all&#34;: 文件将被检索,且页上链接可被查询;   属性值为&#34;none&#34;: 文件不被检索,而且不查询页上的链接;   属性值为&#34;index&#34;: 文件将被检索;   属性值为&#34;follow&#34;: 查询页上的链接;   属性值为&#34;noindex&#34;: 文件不检索,但可被查询链接;   属性值为&#34;nofollow&#34;: [/code] 打印分页 [code]<p style=&#34;page-break-after:always&#34;>page1</p> <p style=&#34;page-break-after:always&#34;>page2</p> [/code] 设置打印 [code] <object id=&#34;factory&#34; style=&#34;display:none&#34; viewastext classid=&#34;clsid:1663ed61-23eb-11d2-b92f-008048fdd814&#34; codebase=&#34;http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360&#34; ></object> <input type=button value=页面设置 onclick=&#34;factory.printing.PageSetup()&#34;> <input type=button value=打印预览 onclick=&#34;factory.printing.Preview()&#34;> <script language=javascript> function window.onload() { // -- advanced features factory.printing.SetMarginMeasure(2) // measure margins in inches factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3 factory.printing.printer = &#34;HP DeskJet 870C&#34; factory.printing.copies = 2 factory.printing.collate = true factory.printing.paperSize = &#34;A4&#34; factory.printing.paperSource = &#34;Manual feed&#34; // -- basic features factory.printing.header = &#34;居左显示&amp;b居中显示&amp;b居右显示页码,第&amp;p页/共&amp;P页&#34; factory.printing.footer = &#34;(自定义页脚)&#34; factory.printing.portrait = false factory.printing.leftMargin = 0.75 factory.printing.topMargin = 1.5 factory.printing.rightMargin = 0.75 factory.printing.bottomMargin = 1.5 } function Print(frame) { factory.printing.Print(true, frame) // print with prompt } </script> <input type=button value=&#34;打印本页&#34; onclick=&#34;factory.printing.Print(false)&#34;> <input type=button value=&#34;页面设置&#34; onclick=&#34;factory.printing.PageSetup()&#34;> <input type=button value=&#34;打印预览&#34; onclick=&#34;factory.printing.Preview()&#34;><br> <a href=&#34;http://www.meadroid.com/scriptx/docs/printdoc.htm?static&#34; target=_blank>具体使用手册,更多信息,点这里</a> [/code] 自带的打印预览 [code]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) 关闭窗体无提示 <style media=print> .Noprint{display:none;}<!--用本样式在打印时隐藏非打印项目--> .PageNext{page-break-after: always;}<!--控制分页--> </style> <object id=&#34;WebBrowser&#34; width=0 height=0 classid=&#34;CLSID:8856F961-340A-11D0-A96B-00C04FD705A2&#34;> </object> <center class=&#34;Noprint&#34; > <input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)> <input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)> <input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)> </p> <p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)> </center> [/code] 去掉打印时的页眉页脚 [code] <script language=&#34;JavaScript&#34;> var HKEY_Root,HKEY_Path,HKEY_Key; HKEY_Root=&#34;HKEY_CURRENT_USER&#34;; HKEY_Path=&#34;\\Software\\Microsoft\\Internet Explorer\\PageSetup\\&#34;; //设置网页打印的页眉页脚为空 function PageSetup_Null() { try { var Wsh=new ActiveXObject(&#34;WScript.Shell&#34;); HKEY_Key=&#34;header&#34;; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&#34;&#34;); HKEY_Key=&#34;footer&#34;; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&#34;&#34;); } catch(e){} } //设置网页打印的页眉页脚为默认值 function PageSetup_Default() { try { var Wsh=new ActiveXObject(&#34;WScript.Shell&#34;); HKEY_Key=&#34;header&#34;; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&#34;&amp;w&amp;b页码,&amp;p/&amp;P&#34;); HKEY_Key=&#34;footer&#34;; Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,&#34;&amp;u&amp;b&amp;d&#34;); } catch(e){} } </script> <input type=&#34;button&#34; value=&#34;清空页码&#34; onclick=PageSetup_Null()> <input type=&#34;button&#34; value=&#34;恢复页码&#34; onclick=PageSetup_Default()> [/code] 计算内容宽和高 [code]<SCRIPT language=&#34;javascript&#34;> function test(obj) { var range = obj.cr&#101;ateTextRange(); alert(&#34;内容区宽度: &#34; + range.boundingWidth + &#34;px\r\n内容区高度: &#34; + range.boundingHeight + &#34;px&#34;); } </SCRIPT> <BODY> <Textarea id=&#34;txt&#34; height=&#34;150&#34;>sdf</textarea><INPUT type=&#34;button&#34; value=&#34;计算内容宽度&#34; onClick=&#34;test(txt)&#34;> </BODY> [/code] 无模式的提示框 [code]function modelessAlert(Msg) { window.showModelessDialog(&#34;javascript:alert(\&#34;&#34;+escape(Msg)+&#34;\&#34;);window.close();&#34;,&#34;&#34;,&#34;status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;&#34;); } [/code] 屏蔽按键 [code]<html> <head> <meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34;> <noscript><meta http-equiv=&#34;refresh&#34; content=&#34;0;url=about:noscript&#34;></noscript> <title>屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键</title> </head> <body> <script language=&#34;Javascript&#34;><!-- //屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键 //Author: meizz(梅花雨) 2002-6-18 function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键 function window.onhelp(){return false} //屏蔽F1帮助 function document.onkeydown() { if ((window.event.altKey)&amp;&amp; ((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ← (window.event.keyCode==39))) //屏蔽 Alt+ 方向键 → { alert(&#34;不准你使用ALT+方向键前进或后退网页!&#34;); event.returnValue=false; } /* 注:这还不是真正地屏蔽 Alt+ 方向键, 因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放, 用鼠标点掉警告框,这种屏蔽方法就失效了。以后若 有哪位高手有真正屏蔽 Alt 键的方法,请告知。*/ if ((event.keyCode==8) || //屏蔽退格删除键 (event.keyCode==116)|| //屏蔽 F5 刷新键 (event.ctrlKey &amp;&amp; event.keyCode==82)){ //Ctrl + R event.keyCode=0; event.returnValue=false; } if (event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11 if (event.ctrlKey &amp;&amp; event.keyCode==78) event.returnValue=false; //屏蔽 Ctrl+n if (event.shiftKey &amp;&amp; event.keyCode==121)event.returnValue=false; //屏蔽 shift+F10 if (window.event.srcElement.tagName == &#34;A&#34; &amp;&amp; window.event.shiftKey) window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一网页 if ((window.event.altKey)&amp;&amp;(window.event.keyCode==115)) //屏蔽Alt+F4 { window.showModelessDialog(&#34;about:blank&#34;,&#34;&#34;,&#34;dialogWidth:1px;dialogheight:1px&#34;); return false; } } </script> 屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键 </body> </html> [/code] 屏蔽打印 [code]<style> @media print{ * {display:none} } </style> [/code] 动的图层,拖动 [code]<span style=&#39;position:absolute;width:200;height:200;background:red&#39; onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>meizz</span> <script language=javascript> var 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; } } </script> [/code] [code] <div id=&#34;myDiv&#34; src=&#34;logo.gif&#34; ondrag=&#34;doDrag();&#34; onmouseover=&#34;this.style.cursor=&#39;hand&#39;&#34; style=&#34;position:absolute;left=100;top=100;&#34; onmousedown=&#34;doMouseDown();&#34;> <a href=&#34;#&#34; onclick=&#34;return false&#34;><h1>wlecome</h1></a> </div> <script language=&#34;JavaScript&#34; type=&#34;text/javascript&#34;> var o&#114;gMouseX; var o&#114;gMouseY; var o&#114;gObjX; var o&#114;gObjY; 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() { o&#114;gMouseX=event.clientX; o&#114;gMouseY=event.clientY; o&#114;gObjX=parseInt(document.all.myDiv.style.left); o&#114;gObjY=parseInt(document.all.myDiv.style.top); } </script> [/code] 文档状态改变 [code] <iframe src=&#34;a.html&#34; id=&#34;f&#34; name=&#34;f&#34; scrolling=&#34;no&#34; frameborder=0 marginwidth=0 marginheight=0></iframe> <script> var doc=window.frames[&#34;f&#34;].document; function s(){ if (doc.readyState==&#34;complete&#34;){ document.all.f.style.height=doc.body.scrollHeight document.all.f.style.width=doc.body.scrollWidth } } doc.onreadystatechange=s </script> [/code] 刷新后不变的文本框 [code]<HTML> <HEAD> <META NAME=&#34;save&#34; CONTENT=&#34;history&#34;> <STYLE> .sHistory {behavior:url(#default#savehistory);} </STYLE> </HEAD> <BODY> <INPUT class=sHistory type=text id=oPersistInput> </BODY> </HTML> [/code] 访问剪贴板 [code](1)拖拽访问 event.dataTransfer.setData(&#34;URL&#34;, oImage.src); sImageURL = event.dataTransfer.getData(&#34;URL&#34;); (2)普通访问 window.clipboardData.setData(&#34;Text&#34;,oSource.innerText); window.clipboardData.getData(&#34;Text&#34;); [/code] 操作COOKIE [code]function SetCookie(sName, sValue) { document.cookie = sName + &#34;=&#34; + escape(sValue) + &#34;; &#34;; } function GetCookie(sName) { var aCookie = document.cookie.split(&#34;; &#34;); for (var i=0; i < aCookie.length; i++) { var aCrumb = aCookie[i].split(&#34;=&#34;); if (sName == aCrumb[0]) return unescape(aCrumb[1]); } } function DelCookie(sName) { document.cookie = sName + &#34;=&#34; + escape(sValue) + &#34;; expires=Fri, 31 Dec 1999 23:59:59 GMT;&#34;; } [/code] setTimeout增加参数 [code]<script> var _st = window.setTimeout; window.setTimeout = function(fRef, mDelay) { if(typeof fRef == &#39;function&#39;){ var argu = Array.prototype.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,&#39;fason&#39;); </script> [/code] 自定义的apply,call [code]Function.prototype.apply = function (obj, argu) { if (obj) obj.constructor.prototype._caller = this; var argus = new Array(); for (var i=0;i<argu.length;i++) argus[i] = &#34;argu[&#34; + i + &#34;]&#34;; var r; eval(&#34;r = &#34; + (obj ? (&#34;obj._caller(&#34; + argus.jo&amp;#105;n(&#34;,&#34;) + &#34;);&#34;) : (&#34;this(&#34; + argus.jo&amp;#105;n(&#34;,&#34;) + &#34;);&#34;))); return r; }; Function.prototype.call = function (obj) { var argu = new Array(); for (var i=1;i<arguments.length;i++) argu[i-1] = arguments[i]; return this.apply(obj, argu); }; [/code] 下载文件 [code]function DownURL(strRemoteURL,strLocalURL) { try { var xmlHTTP=new ActiveXObject(&#34;Microsoft.XMLHTTP&#34;); xmlHTTP.open(&#34;Get&#34;,strRemoteURL,false); xmlHTTP.send(); var adodbStream=new ActiveXObject(&#34;ADODB.Stream&#34;); adodbStream.Type=1;//1=adTypeBinary adodbStream.Open(); adodbStream.write(xmlHTTP.responseBody); adodbStream.SaveToFile(strLocalURL,2); adodbStream.Close(); adodbStream=null; xmlHTTP=null; } catch(e) { window.confirm(&#34;下载URL出错!&#34;); } //window.confirm(&#34;下载完成.&#34;); } [/code] 检验连接是否有效 [code]function getXML(URL) { var xmlhttp = new ActiveXObject(&#34;microsoft.xmlhttp&#34;); xmlhttp.Open(&#34;GET&#34;,URL, false); try { xmlhttp.Send(); } catch(e){} finally { var result = xmlhttp.responseText; if(result) { if(xmlhttp.Status==200) { return(true); } else { return(false); } } else { return(false); } } } [/code] POST代替FORM [code]<SCRIPT language=&#34;VBScript&#34;> Function URLEncoding(vstrIn) strReturn = &#34;&#34; For i = 1 To Len(vstrIn) ThisChr = Mid(vStrIn,i,1) If Abs(Asc(ThisChr)) < &amp;HFF Then strReturn = strReturn &amp; ThisChr Else innerCode = Asc(ThisChr) If innerCode < 0 Then innerCode = innerCode + &amp;H10000 End If Hight8 = (innerCode And &amp;HFF00)\ &amp;HFF Low8 = innerCode And &amp;HFF strReturn = strReturn &amp; &#34;%&#34; &amp; Hex(Hight8) &amp; &#34;%&#34; &amp; Hex(Low8) End If Next URLEncoding = strReturn End Function Function bytes2BSTR(vIn) strReturn = &#34;&#34; For i = 1 To LenB(vIn) ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode < &amp;H80 Then strReturn = strReturn &amp; Chr(ThisCharCode) Else NextCharCode = AscB(MidB(vIn,i+1,1)) strReturn = strReturn &amp; Chr(CLng(ThisCharCode) * &amp;H100 + CInt(NextCharCode)) i = i + 1 End If Next bytes2BSTR = strReturn End Function dim strA,oReq strA = URLEncoding(&#34;submit1=Submit&amp;text1=中文&#34;) set o&#114;eq = Cr&#101;ateObject(&#34;MSXML2.XMLHTTP&#34;) o&#114;eq.open &#34;POST&#34;,&#34;http://ServerName/VDir/TstResult.asp&#34;,false o&#114;eq.setRequestHeader &#34;Content-Length&#34;,Len(strA) o&#114;eq.setRequestHeader &#34;CONTENT-TYPE&#34;,&#34;application/x-www-form-urlencoded&#34; o&#114;eq.send strA msgbox bytes2BSTR(oReq.responseBody) </SCRIPT> [/code] //readyState是xmlhttp返回数据的进度,0=载入中,1=未初始化,2=已载入,3=运行中,4=完成 //组件是否安装 [code]isComponentInstalled(&#34;{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}&#34;, &#34;componentID&#34;)) [/code] 检查网页是否存在 [code]function CheckURL(URL) { var xmlhttp = new ActiveXObject(&#34;Microsoft.XMLHTTP&#34;); xmlhttp.Open(&#34;GET&#34;,URL, false); try { xmlhttp.Send(); var result = xmlhttp.status; } catch(e) {return(false); } if(result==200) { return true; } xmlhttp = null; return false; } [/code] 连接数据库 [code]<script language=&#34;javascript&#34;> //用 JavaScript 写服务器端连接数据库的代码示例 var conn = new ActiveXObject(&#34;ADODB.Connection&#34;); conn.Open(&#34;Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; &#34; +&#34;Password=; Initial Catalog=pubs&#34;); var rs = new ActiveXObject(&#34;ADODB.Recordset&#34;); var sql=&#34;sel&#101;ct * from authors&#34;; rs.open(sql, conn); shtml = &#34;<table width=&#39;100%&#39; border=1>&#34;; shtml +=&#34;<tr bgcolor=&#39;#f4f4f4&#39;><td>au_id</td><td>au_lname</td><td>au_fname</td><td>phone</td><td>address</td><td> city</td><td>state</td><td>zip</td></tr>&#34;; while(!rs.EOF) { shtml += &#34;<tr><td>&#34; + rs(&#34;au_id&#34;) + &#34;</td><td>&#34; + rs(&#34;au_lname&#34;) + &#34;</td><td>&#34; + rs(&#34;au_fname&#34;) + &#34;</td><td>&#34; + rs(&#34;phone&#34;) + &#34;</td><td>&#34; + rs(&#34;address&#34;) + &#34;</td><td>&#34; + rs(&#34;city&#34;) + &#34;</td><td>&#34; + rs(&#34;state&#34;) + &#34;</td><td>&#34; + rs(&#34;zip&#34;) + &#34;</td></tr>&#34;; rs.moveNext; } shtml += &#34;</table>&#34;; document.write(shtml); rs.close(); rs = null; conn.close(); conn = null; </script> [/code] 使用数据岛 [code]<html> <body> srno:<input type=text datasrc=#xmldate DataFLD=srno size=&#34;76&#34;><BR> times:<input type=text datasrc=#xmldate DataFLD=times size=&#34;76&#34;><BR> <input id=&#34;first&#34; TYPE=button value=&#34;<< 第一条记录&#34; onclick=&#34;xmldate.recordset.moveFirst()&#34;> <input id=&#34;prev&#34; TYPE=button value=&#34;<上一条记录&#34; onclick=&#34;xmldate.recordset.movePrevious()&#34;> <input id=&#34;next&#34; TYPE=button value=&#34;下一条记录>&#34; onclick=&#34;xmldate.recordset.moveNext()&#34;> <input id=&#34;last&#34; TYPE=button value=&#34;最后一条记录>>&#34; onclick=&#34;xmldate.recordset.moveLast()&#34;> <input id=&#34;Add&#34; TYPE=button value=&#34;添加新记录&#34; onclick=&#34;xmldate.recordset.addNew()&#34;> <XML ID=&#34;xmldate&#34;> <infolist> <info ><srno>20041025-01</srno><times>null</times></info> <info ><srno>20041101-09</srno><times>2004年10月1日2点22分0秒</times></info> </infolist> </XML> </body> </html> [/code] 获得参数 [code]<body> <a href=&#34;javascript:location.href=location.href + &#39;?a=1&amp;b=2&#39;&#34;>search</a> <script language=&#34;JavaScript&#34;> <!-- var a = location.search.substr(1); if(a.length>0) { var re = /([^&amp;]*?)\=([^&amp;]*)/g var s = a.match(re); for(var i= 0;i<s.length;i++) { alert(s[i]); alert(s[i].split(&#34;=&#34;)[1]); } } //--> </script> </body> [/code] 可编辑Sel&#101;ct [code]<input type=text name=re_name style=&#34;width:100px;height:21px;font-size:10pt;&#34;><span style=&#34;width:18px;border:0px solid red;&#34;><sel&#101;ct name=&#34;r00&#34; style=&#34;margin-left:-100px;width:118px; background-color:#FFEEEE;&#34; onChange=&#34;document.all.re_name.value=this.value;&#34;> <option value=&#34;1&#34;>11111111<option> <option value=&#34;2&#34;>222222</option> <option value=&#34;3&#34;>333333</option> </sel&#101;ct> </span> [/code] 设置光标位置 [code]function getCaret(textbox) { var control = document.activeElement; textbox.focus(); var rang = document.sel&#101;ction.cr&#101;ateRange(); rang.setEndPoint(&#34;StartToStart&#34;,textbox.cr&#101;ateTextRange()) control.focus(); return rang.text.length; } function setCaret(textbox,pos) { try { var r =textbox.cr&#101;ateTextRange(); r.moveStart(&#39;character&#39;,pos); r.collapse(true); r.sel&#101;ct(); } catch(e) {} } function sel&#101;ctLength(textbox,start,len) { try { var r =textbox.cr&#101;ateTextRange(); r.moveEnd(&#39;character&#39;,len-(textbox.value.length-start)); r.moveStart(&#39;character&#39;,start); r.sel&#101;ct(); } catch(e) {//alert(e.description)} } function ins&#101;rtAtCaret(textbox,text) { textbox.focus(); document.sel&#101;ction.cr&#101;ateRange().text = text; } [/code] 页内查找 [code]function findInPage(str) { var txt, i, found,n = 0; if (str == &#34;&#34;) { return false; } txt = document.body.cr&#101;ateTextRange(); for (i = 0; i <= n &amp;&amp; (found = txt.findText(str)) != false; i++) { txt.moveStart(&#34;character&#34;, 1); txt.moveEnd(&#34;textedit&#34;); } if (found) { txt.moveStart(&#34;character&#34;, -1); txt.findText(str); txt.sel&#101;ct(); txt.scrollIntoView(); n++; } else { if (n > 0) { n = 0; findInPage(str); } else { alert(str + &#34;... 您要找的文字不存在。\n \n请试着输入页面中的关键字再次查找!&#34;); } } return false; } [/code] 操作EXECL [code]<script language=&#34;javascript&#34;> function jStartExcel() { var xls = new ActiveXObject ( &#34;Excel.Application&#34; ); xls.visible = true; var newBook = xls.Workbooks.Add; newBook.Worksheets.Add; newBook.Worksheets(1).Activate; xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation = 2; xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize = 5; newBook.Worksheets(1).Columns(&#34;A&#34;).columnwidth=50; newBook.Worksheets(1).Columns(&#34;A&#34;).WrapText = true; newBook.Worksheets(1).Columns(&#34;B&#34;).columnwidth=50; newBook.Worksheets(1).Columns(&#34;B&#34;).WrapText = true; newBook.Worksheets(1).Range(&#34;A1:B1000&#34;).NumberFormat = &#34;0&#34;; newBook.Worksheets(1).Range(&#34;A1:B1000&#34;).HorizontalAlignment = -4131; newBook.Worksheets(1).Cells(1,1).Interior.ColorIndex=&#34;15&#34;; newBook.Worksheets(1).Cells(1,1).value=&#34;First Column, First Cell&#34;; newBook.Worksheets(1).Cells(2,1).value=&#34;First Column, Second Cell&#34;; newBook.Worksheets(1).Cells(1,2).value=&#34;Second Column, First Cell&#34;; newBook.Worksheets(1).Cells(2,2).value=&#34;Second Column, Second Cell&#34;; newBook.Worksheets(1).Name=&#34;My First WorkSheet&#34;; } </script> [/code] 自定义提示条 [code]<a href=&#34;#&#34; title=&#34;这是提示&#34;>tip</a> <script Language=&#34;JavaScript&#34;> //***********默认设置定义.********************* tPopWait=50;//停留tWait豪秒后显示提示。 tPopShow=5000;//显示tShow豪秒后关闭提示 showPopStep=20; popOpacity=99; //***************内部变量定义***************** sPop=null; curShow=null; tFadeOut=null; tFadeIn=null; tFadeWaiting=null; document.write(&#34;<style type=&#39;text/css&#39;id=&#39;defaultPopStyle&#39;>&#34;); document.write(&#34;.cPopText { background-color: #F8F8F5;color:#000000; border: 1px #000000 solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}&#34;); document.write(&#34;</style>&#34;); document.write(&#34;<div id=&#39;dypopLayer&#39; style=&#39;position:absolute;z-index:1000;&#39; class=&#39;cPopText&#39;></div>&#34;); function showPopupText(){ var o=event.srcElement; MouseX=event.x; MouseY=event.y; if(o.alt!=null &amp;&amp; o.alt!=&#34;&#34;){o.dypop=o.alt;o.alt=&#34;&#34;}; if(o.title!=null &amp;&amp; o.title!=&#34;&#34;){o.dypop=o.title;o.title=&#34;&#34;}; if(o.dypop!=sPop) { sPop=o.dypop; clearTimeout(curShow); clearTimeout(tFadeOut); clearTimeout(tFadeIn); clearTimeout(tFadeWaiting); if(sPop==null || sPop==&#34;&#34;) { dypopLayer.innerHTML=&#34;&#34;; dypopLayer.style.filter=&#34;Alpha()&#34;; dypopLayer.filters.Alpha.opacity=0; } else { if(o.dyclass!=null) popStyle=o.dyclass else popStyle=&#34;cPopText&#34;; curShow=setTimeout(&#34;showIt()&#34;,tPopWait); } } } function showIt(){ dypopLayer.className=popStyle; dypopLayer.innerHTML=sPop; popWidth=dypopLayer.clientWidth; popHeight=dypopLayer.clientHeight; if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24 else popLeftAdjust=0; if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24 else popTopAdjust=0; dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust; dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust; dypopLayer.style.filter=&#34;Alpha(Opacity=0)&#34;; fadeOut(); } function fadeOut(){ if(dypopLayer.filters.Alpha.opacity<popOpacity) { dypopLayer.filters.Alpha.opacity+=showPopStep; tFadeOut=setTimeout(&#34;fadeOut()&#34;,1); } else { dypopLayer.filters.Alpha.opacity=popOpacity; tFadeWaiting=setTimeout(&#34;fadeIn()&#34;,tPopShow); } } function fadeIn(){ if(dypopLayer.filters.Alpha.opacity>0) { dypopLayer.filters.Alpha.opacity-=1; tFadeIn=setTimeout(&#34;fadeIn()&#34;,1); } } document.onmouseover=showPopupText; </script> [/code] 插入文字 [code]document.onclick =function(){ var oSource = window.event.srcElement; if(oSource.tagName!=&#34;DIV&#34;) return false; var sel = document.sel&#101;ction; if (sel!=null) { var rng = sel.cr&#101;ateRange(); if (rng!=null) rng.pasteHTML(&#34;<font color=red>插入文字</font>&#34;); } } //netscapte下操作xml doc = new ActiveXObject(&#34;Msxml2.DOMDocument&#34;); doc = new ActiveXObject(&#34;Microsoft.XMLDOM&#34;) ->> doc = (new DOMParser()).parseFromString(sXML,&#39;text/xml&#39;) [/code] 判断键值 [code]<html> <meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34;> <head> <script language=&#34;javascript&#34;> var ie =navigator.appName==&#34;Microsoft Internet Explorer&#34;?true:false; function keyDown(e) { if(!ie) { var nkey=e.which; var iekey=&#39;现在是ns浏览器&#39;; var realkey=String.fromCharCode(e.which); } if(ie) { var iekey=event.keyCode; var nkey=&#39;现在是ie浏览器&#39;; var realkey=String.fromCharCode(event.keyCode); if(event.keyCode==32){realkey=&#39;\&#39; 空格\&#39;&#39;} if(event.keyCode==13){realkey=&#39;\&#39; 回车\&#39;&#39;} if(event.keyCode==27){realkey=&#39;\&#39; Esc\&#39;&#39;} if(event.keyCode==16){realkey=&#39;\&#39; Shift\&#39;&#39;} if(event.keyCode==17){realkey=&#39;\&#39; Ctrl\&#39;&#39;} if(event.keyCode==18){realkey=&#39;\&#39; Alt\&#39;&#39;} } alert(&#39;ns浏览器中键值:&#39;+nkey+&#39;\n&#39;+&#39;ie浏览器中键值:&#39;+iekey+&#39;\n&#39;+&#39;实际键为&#39;+realkey); } document.onkeydown = keyDown; </script> </head> <body> //Javascript Document. <hr> <center> <h3>请按任意一个键。。。。</h3> </center> </body> </html> [/code] 禁止FSO [code]1.注销组件 regsvr32 /u scrrun.dll 2.修改PROGID HKEY_CLASSES_ROOT\Scripting.FileSystemObject Scripting.FileSystemObject 3.对于使用object的用户,修改HKEY_CLASSES_ROOT\Scripting. [/code] 省略号 [code]<DIV STYLE=&#34;width: 120px; height: 50px; border: 1px solid blue; overflow: hidden; text-overflow:ellipsis&#34;> <NOBR>就是比如有一行文字,很长,表格内一行显示不下.</NOBR> </DIV> [/code] 检测media play版本 [code] <IE:clientCaps ID=&#34;oClientCaps&#34; style=&#34;{behavior:url(#default#clientcaps)}&#34; /> <SCRIPT> var flash=&#34;&#34;; WMPVersion= oClientCaps.getComponentVersion(&#34;{22D6F312-B0F6-11D0-94AB-0080C74C7E95}&#34;,&#34;ComponentID&#34;); if (WMPVersion != &#34;&#34;) { flash = &#34;&#34;; var version = WMPVersion.split(&#34;,&#34;); var i; for (i = 0; i < version.length; i++) { if (i != 0) flash += &#34;.&#34;; flash += version[i]; } document.write(&#34;您的Windows Media Player 版本是:&#34;+flash+&#34;<p>&#34;); } </SCRIPT> [/code] 图象按比例 [code] <script language=&#34;JavaScript&#34;> <!-- //图片按比例缩放 var flag=false; function DrawImage(ImgD){ var image=new Image(); var iwidth = 80; //定义允许图片宽度 var iheight = 80; //定义允许图片高度 image.src=ImgD.src; if(image.width>0 &amp;&amp; image.height>0){ flag=true; if(image.width/image.height>= iwidth/iheight){ if(image.width>iwidth){ ImgD.width=iwidth; ImgD.height=(image.height*iwidth)/image.width; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+&#34;×&#34;+image.height; } else{ if(image.height>iheight){ ImgD.height=iheight; ImgD.width=(image.width*iheight)/image.height; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+&#34;×&#34;+image.height; } } } //--> </script> <img src=&#34;..&#34; onload = &#34;DrawImage(this)&#34;> [/code] 细线Sel&#101;ct [code]<span style=&#34;border:1px solid #000000; position:absolute; overflow:hidden;&#34; > <sel&#101;ct style=&#34;margin:-2px;&#34;> <option>1111</option> <option>11111111111111</option> <option>111111111</option> </sel&#101;ct></span> [/code] Import [code]function Import() { for( var i=0; i<arguments.length; i++ ) { var file = arguments[i]; if ( file.match(/\.js$/i)) document.write(&#39;<script type=\&#34;text/javascript\&#34; src=\&#34;&#39; + file + &#39;\&#34;></sc&#39; + &#39;ript>&#39;); else document.write(&#39;<style type=\&#34;text/css\&#34;>@import \&#34;&#39; + file + &#39;\&#34; ;</style>&#39;); } }; [/code] js枚举 [code]function getComputerName() { var objWMIService = GetObject(&#34;Winmgmts:root\cimv2&#34;); for(e = new Enumerator(objWMIService) ; !e.atEnd() ; e.moveNext()) { var getComputer = e.item(); return getComputer.Name; } } [/code] 条件编译 [code]<script language=javascript> /*@cc_on @*/ /*@if (@_win32 &amp;&amp; @_jscript_version>5) function window.confirm(str) { execScript(&#34;n = msgbox(&#39;&#34;+ str +&#34;&#39;, 257)&#34;, &#34;vbscript&#34;); return(n == 1); } @end @*/ </script> [/code] 取得innerText [code] <SCRIPT LANGUAGE=&#34;JavaScript&#34;> <!-- var xmlDoc = new ActiveXObject(&#34;Msxml2.DOMDocument.4.0&#34;); var currNode; xmlDoc.async = false; xmlDoc.async = false; xmlDoc.loadXML(&#34;<TABLENAME> 你好你阿三 大法 司法等四 </TABLENAME>&#34;); currNode = xmlDoc.documentElement; var s = currNode.xml; var r = /\<([^\>\s]*?)[^\>]*?\>([^\<]*?)\<\/\1\>/ var b = s.replace(r,&#34;$2&#34;); alert(b); //--> </SCRIPT> //mergeAttributes 复制所有读/写标签属性到指定元素。 <SCRIPT> function fnMerge(){ oSource.children[1].mergeAttributes(oSource.children[0]); } </SCRIPT> <SPAN ID=oSource> <DIV ID=&#34;oDiv&#34; ATTRIBUTE1=&#34;true&#34; ATTRIBUTE2=&#34;true&#34; onclick=&#34;alert(&#39;click&#39;);&#34; onmouseover=&#34;this.style.color=&#39;#0000FF&#39;;&#34; onmouseout=&#34;this.style.color=&#39;#000000&#39;;&#34; > This is a sample <B>DIV</B> element. </DIV> <DIV ID=&#34;oDiv2&#34;> This is another sample <B>DIV</B> element. </DIV> </SPAN> <INPUT TYPE=&#34;button&#34; VALUE=&#34;Merge Attributes&#34; onclick=&#34;fnMerge()&#34; > [/code] 检查链接是否有效 [code]<a href=&#34;http://www.pconline.com.cn/welcome.asp&#34; onclick=&#34;mm(this, &#39;http://www.pconline.com.cn/&#39;)&#34;>test</a> <script language=&#34;javascript&#34;> function getURL(url) { var xmlhttp = new ActiveXObject(&#34;Microsoft.XMLHTTP&#34;); xmlhttp.open(&#34;GET&#34;,url,false); xmlhttp.send(); if (xmlhttp.readyState==4) return xmlhttp.Status==200; return false; } function mm(e, url) { if(!getURL(e.href)) e.href = url; } </script> [/code] 判断是否输入值再激活按钮 [code]<script> function check(){ s.disabled = (t1.value == &#39;&#39; || t2.value == &#39;&#39; || t3.value == &#39;&#39;) } </script> <input name=&#34;t1&#34; onpropertychange=&#34;check();&#34;> <input name=&#34;t2&#34; onpropertychange=&#34;check();&#34;> <input name=&#34;t3&#34; onpropertychange=&#34;check();&#34;> <input type=&#34;submit&#34; name=&#34;s&#34; disabled> [/code] 屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键 [code] <html> <head> <meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34;> <noscript><meta http-equiv=&#34;refresh&#34; content=&#34;0;url=about:noscript&#34;></noscript> <title>屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键</title> </head> <body> <script language=&#34;Javascript&#34;><!-- //屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键 //Author: meizz(梅花雨) 2002-6-18 function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键 function window.onhelp(){return false} //屏蔽F1帮助 function document.onkeydown() { if ((window.event.altKey)&amp;&amp; ((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ← (window.event.keyCode==39))) //屏蔽 Alt+ 方向键 → { alert(&#34;不准你使用ALT+方向键前进或后退网页!&#34;); event.returnValue=false; } /* 注:这还不是真正地屏蔽 Alt+ 方向键, 因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放, 用鼠标点掉警告框,这种屏蔽方法就失效了。以后若 有哪位高手有真正屏蔽 Alt 键的方法,请告知。*/ if ((event.keyCode==8) || //屏蔽退格删除键 (event.keyCode==116)|| //屏蔽 F5 刷新键 (event.ctrlKey &amp;&amp; event.keyCode==82)){ //Ctrl + R event.keyCode=0; event.returnValue=false; } if (event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11 if (event.ctrlKey &amp;&amp; event.keyCode==78) event.returnValue=false; //屏蔽 Ctrl+n if (event.shiftKey &amp;&amp; event.keyCode==121)event.returnValue=false; //屏蔽 shift+F10 if (window.event.srcElement.tagName == &#34;A&#34; &amp;&amp; window.event.shiftKey) window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一网页 if ((window.event.altKey)&amp;&amp;(window.event.keyCode==115)) //屏蔽Alt+F4 { window.showModelessDialog(&#34;about:blank&#34;,&#34;&#34;,&#34;dialogWidth:1px;dialogheight:1px&#34;); return false; } } </script> 屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键 </body> </html> [/code] 自定义热键(请按a) [code]自定义热键(请按a) <SCRIPT language=&#34;JavaScript&#34;> <!-- var hotkey=97 var destination=&#34;http://www.wyev.com&#34; if (document.layers) document.captureEvents(Event.KEYPRESS) function backhome(e){ if (document.layers){ if (e.which==hotkey) window.location=destination } else if (document.all){ if (event.keyCode==hotkey) window.location=destination } } document.onkeypress=backhome //--> </SCRIPT> [/code] 下面的是用javascript传递参数。如果本文件为test.htm,如果访问 test.htm?12 则javascript会得到?后的值并用document.all替换iframe的src值。 [code]<iframe height=&#34;750&#34; width=&#34;760&#34; scrolling=&#34;no&#34; src=&#34;view.jsp&#34; id=&#34;u&#34; frameborder=&#34;0&#34;></iframe> <script language=&#34;javascript&#34;> var url=window.location.href; var s=url.indexOf(&#34;?&#34;); if(s!=-1) { var src=url.substring(s+1); document.all.u.src=&#34;view.jsp?id=&#34;+src; } </script> [/code] 取得字符串实际长度(汉字算两个字节,英文字母算一个字节) [code]<script> var s=&#39;中文,English&#39;; alert(&#34;[&#34;+s+&#34;]的长度:&#34;+s.replace(/[^\x00-\xff]/gi,&#39;xx&#39;).length) </script>[/code] 简繁转换 [code]<!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;> <html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;> <head> <meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=gb2312&#34; /> <title>无标题文档</title> </head> <body> <a id=&#34;StranLink&#34;>繁体</a> 网页代码检测 中国DotNet俱乐部——首页点乃特学习.z6ionestabw3cn蓝色ideaMSDN 雷神竞技场中文站论坛 z987论坛 VeryCD游戏专区 Google <script type=&#34;text/javascript&#34;> //模仿語言包式的簡繁轉換功能插件! //Edited by Stardy --2005-04-16 , Web :http://www.stardy.com , QQ:2885465 //Re-Edited by Stud --2005-10-10 , Web :http://www.metro.com.tw var Default_isFT = 0 //默認是否繁體,0-簡體,1-繁體 var StranIt_Delay = 30 //翻譯延時毫秒(設這個的目的是讓網頁先流暢的顯現出來) //-------代碼開始,以下別改------- //轉換文本 function StranText(txt,toFT,chgTxt) { if(txt==&#34;&#34;||txt==null)return &#34;&#34; toFT=toFT==null?BodyIsFt:toFT if(chgTxt)txt=txt.replace((toFT?&#34;簡&#34;:&#34;繁&#34;),(toFT?&#34;繁&#34;:&#34;簡&#34;)) if(toFT){return Simplized(txt)} else {return Traditionalized(txt)} } //轉換對象,使用遞歸,逐層剝到文本 function StranBody(fobj) { if(typeof(fobj)==&#34;object&#34;){var obj=fobj.childNodes} else { var tmptxt=StranLink_Obj.innerHTML.toString() if(tmptxt.indexOf(&#34;簡&#34;)<0) { BodyIsFt=0 StranLink_Obj.innerHTML=StranText(tmptxt,0,1) StranLink_Obj.title=StranText(StranLink_Obj.title,0,1) } else { BodyIsFt=1 StranLink_Obj.innerHTML=StranText(tmptxt,1,1) StranLink_Obj.title=StranText(StranLink_Obj.title,1,1) } setCookie(JF_cn,BodyIsFt,7) var obj=document.body.childNodes } for(var i=0;i<obj.length;i++) { var OO=obj.item(i) if(&#34;||BR|HR|TEXTAREA|&#34;.indexOf(&#34;|&#34;+OO.tagName+&#34;|&#34;)>0||OO==StranLink_Obj)continue; if(OO.title!=&#34;&#34;&amp;&amp;OO.title!=null)OO.title=StranText(OO.title); if(OO.alt!=&#34;&#34;&amp;&amp;OO.alt!=null)OO.alt=StranText(OO.alt); if(OO.tagName==&#34;INPUT&#34;&amp;&amp;OO.value!=&#34;&#34;&amp;&amp;OO.type!=&#34;text&#34;&amp;&amp;OO.type!=&#34;hidden&#34;)OO.value=StranText(OO.value); if(OO.nodeType==3){OO.data=StranText(OO.data)} else StranBody(OO) } } function JTPYStr() { return &#39;皑蔼碍爱翱袄奥坝罢摆败颁办绊帮绑镑谤剥饱宝报鲍辈贝钡狈备惫绷笔毕毙闭边编贬变辩辫鳖瘪濒滨宾摈饼拨钵铂驳卜补参蚕残惭惨灿苍舱仓沧厕侧册测层诧搀掺蝉馋谗缠铲产阐颤场尝长偿肠厂畅钞车彻尘陈衬撑称惩诚骋痴迟驰耻齿炽冲虫宠畴踌筹绸丑橱厨锄雏础储触处传疮闯创锤纯绰辞词赐聪葱囱从丛凑窜错达带贷担单郸掸胆惮诞弹当挡党荡档捣岛祷导盗灯邓敌涤递缔点垫电淀钓调迭谍叠钉顶锭订东动栋冻斗犊独读赌镀锻断缎兑队对吨顿钝夺鹅额讹恶饿儿尔饵贰发罚阀珐矾钒烦范贩饭访纺飞废费纷坟奋愤粪丰枫锋风疯冯缝讽凤肤辐抚辅赋复负讣妇缚该钙盖干赶秆赣冈刚钢纲岗皋镐搁鸽阁铬个给龚宫巩贡钩沟构购够蛊顾剐关观馆惯贯广规硅归龟闺轨诡柜贵刽辊滚锅国过骇韩汉阂鹤贺横轰鸿红后壶护沪户哗华画划话怀坏欢环还缓换唤痪焕涣黄谎挥辉毁贿秽会烩汇讳诲绘荤浑伙获货祸击机积饥讥鸡绩缉极辑级挤几蓟剂济计记际继纪夹荚颊贾钾价驾歼监坚笺间艰缄茧检碱硷拣捡简俭减荐槛鉴践贱见键舰剑饯渐溅涧浆蒋桨奖讲酱胶浇骄娇搅铰矫侥脚饺缴绞轿较秸阶节茎惊经颈静镜径痉竞净纠厩旧驹举据锯惧剧鹃绢杰洁结诫届紧锦仅谨进晋烬尽劲荆觉决诀绝钧军骏开凯颗壳课垦恳抠库裤夸块侩宽矿旷况亏岿窥馈溃扩阔蜡腊莱来赖蓝栏拦篮阑兰澜谰揽览懒缆烂滥捞劳涝乐镭垒类泪篱离里鲤礼丽厉励砾历沥隶俩联莲连镰怜涟帘敛脸链恋炼练粮凉两辆谅疗辽镣猎临邻鳞凛赁龄铃凌灵岭领馏刘龙聋咙笼垄拢陇楼娄搂篓芦卢颅庐炉掳卤虏鲁赂禄录陆驴吕铝侣屡缕虑滤绿峦挛孪滦乱抡轮伦仑沦纶论萝罗逻锣箩骡骆络妈玛码蚂马骂吗买麦卖迈脉瞒馒蛮满谩猫锚铆贸么霉没镁门闷们锰梦谜弥觅绵缅庙灭悯闽鸣铭谬谋亩钠纳难挠脑恼闹馁腻撵捻酿鸟聂啮镊镍柠狞宁拧泞钮纽脓浓农疟诺欧鸥殴呕沤盘庞国爱赔喷鹏骗飘频贫苹凭评泼颇扑铺朴谱脐齐骑岂启气弃讫牵扦钎铅迁签谦钱钳潜浅谴堑枪呛墙蔷强抢锹桥乔侨翘窍窃钦亲轻氢倾顷请庆琼穷趋区躯驱龋颧权劝却鹊让饶扰绕热韧认纫荣绒软锐闰润洒萨鳃赛伞丧骚扫涩杀纱筛晒闪陕赡缮伤赏烧绍赊摄慑设绅审婶肾渗声绳胜圣师狮湿诗尸时蚀实识驶势释饰视试寿兽枢输书赎属术树竖数帅双谁税顺说硕烁丝饲耸怂颂讼诵擞苏诉肃虽绥岁孙损笋缩琐锁獭挞抬摊贪瘫滩坛谭谈叹汤烫涛绦腾誊锑题体屉条贴铁厅听烃铜统头图涂团颓蜕脱鸵驮驼椭洼袜弯湾顽万网韦违围为潍维苇伟伪纬谓卫温闻纹稳问瓮挝蜗涡窝呜钨乌诬无芜吴坞雾务误锡牺袭习铣戏细虾辖峡侠狭厦锨鲜纤咸贤衔闲显险现献县馅羡宪线厢镶乡详响项萧销晓啸蝎协挟携胁谐写泻谢锌衅兴汹锈绣虚嘘须许绪续轩悬选癣绚学勋询寻驯训讯逊压鸦鸭哑亚讶阉烟盐严颜阎艳厌砚彦谚验鸯杨扬疡阳痒养样瑶摇尧遥窑谣药爷页业叶医铱颐遗仪彝蚁艺亿忆义诣议谊译异绎荫阴银饮樱婴鹰应缨莹萤营荧蝇颖哟拥佣痈踊咏涌优忧邮铀犹游诱舆鱼渔娱与屿语吁御狱誉预驭鸳渊辕园员圆缘远愿约跃钥岳粤悦阅云郧匀陨运蕴酝晕韵杂灾载攒暂赞赃脏凿枣灶责择则泽贼赠扎札轧铡闸诈斋债毡盏斩辗崭栈战绽张涨帐账胀赵蛰辙锗这贞针侦诊镇阵挣睁狰帧郑证织职执纸挚掷帜质钟终种肿众诌轴皱昼骤猪诸诛烛瞩嘱贮铸筑驻专砖转赚桩庄装妆壮状锥赘坠缀谆浊兹资渍踪综总纵邹诅组钻致钟么为只凶准启板里雳余链泄&#39;; } function FTPYStr() { return &#39;皚藹礙愛翱襖奧壩罷擺敗頒辦絆幫綁鎊謗剝飽寶報鮑輩貝鋇狽備憊繃筆畢斃閉邊編貶變辯辮鱉癟瀕濱賓擯餅撥缽鉑駁蔔補參蠶殘慚慘燦蒼艙倉滄廁側冊測層詫攙摻蟬饞讒纏鏟產闡顫場嘗長償腸廠暢鈔車徹塵陳襯撐稱懲誠騁癡遲馳恥齒熾沖蟲寵疇躊籌綢醜櫥廚鋤雛礎儲觸處傳瘡闖創錘純綽辭詞賜聰蔥囪從叢湊竄錯達帶貸擔單鄲撣膽憚誕彈當擋黨蕩檔搗島禱導盜燈鄧敵滌遞締點墊電澱釣調疊諜疊釘頂錠訂東動棟凍鬥犢獨讀賭鍍鍛斷緞兌隊對噸頓鈍奪鵝額訛惡餓兒爾餌貳發罰閥琺礬釩煩範販飯訪紡飛廢費紛墳奮憤糞豐楓鋒風瘋馮縫諷鳳膚輻撫輔賦複負訃婦縛該鈣蓋幹趕稈贛岡剛鋼綱崗皋鎬擱鴿閣鉻個給龔宮鞏貢鉤溝構購夠蠱顧剮關觀館慣貫廣規矽歸龜閨軌詭櫃貴劊輥滾鍋國過駭韓漢閡鶴賀橫轟鴻紅後壺護滬戶嘩華畫劃話懷壞歡環還緩換喚瘓煥渙黃謊揮輝毀賄穢會燴彙諱誨繪葷渾夥獲貨禍擊機積饑譏雞績緝極輯級擠幾薊劑濟計記際繼紀夾莢頰賈鉀價駕殲監堅箋間艱緘繭檢堿鹼揀撿簡儉減薦檻鑒踐賤見鍵艦劍餞漸濺澗漿蔣槳獎講醬膠澆驕嬌攪鉸矯僥腳餃繳絞轎較秸階節莖驚經頸靜鏡徑痙競淨糾廄舊駒舉據鋸懼劇鵑絹傑潔結誡屆緊錦僅謹進晉燼盡勁荊覺決訣絕鈞軍駿開凱顆殼課墾懇摳庫褲誇塊儈寬礦曠況虧巋窺饋潰擴闊蠟臘萊來賴藍欄攔籃闌蘭瀾讕攬覽懶纜爛濫撈勞澇樂鐳壘類淚籬離裏鯉禮麗厲勵礫曆瀝隸倆聯蓮連鐮憐漣簾斂臉鏈戀煉練糧涼兩輛諒療遼鐐獵臨鄰鱗凜賃齡鈴淩靈嶺領餾劉龍聾嚨籠壟攏隴樓婁摟簍蘆盧顱廬爐擄鹵虜魯賂祿錄陸驢呂鋁侶屢縷慮濾綠巒攣孿灤亂掄輪倫侖淪綸論蘿羅邏鑼籮騾駱絡媽瑪碼螞馬罵嗎買麥賣邁脈瞞饅蠻滿謾貓錨鉚貿麼黴沒鎂門悶們錳夢謎彌覓綿緬廟滅憫閩鳴銘謬謀畝鈉納難撓腦惱鬧餒膩攆撚釀鳥聶齧鑷鎳檸獰甯擰濘鈕紐膿濃農瘧諾歐鷗毆嘔漚盤龐國愛賠噴鵬騙飄頻貧蘋憑評潑頗撲鋪樸譜臍齊騎豈啟氣棄訖牽扡□鉛遷簽謙錢鉗潛淺譴塹槍嗆牆薔強搶鍬橋喬僑翹竅竊欽親輕氫傾頃請慶瓊窮趨區軀驅齲顴權勸卻鵲讓饒擾繞熱韌認紉榮絨軟銳閏潤灑薩鰓賽傘喪騷掃澀殺紗篩曬閃陝贍繕傷賞燒紹賒攝懾設紳審嬸腎滲聲繩勝聖師獅濕詩屍時蝕實識駛勢釋飾視試壽獸樞輸書贖屬術樹豎數帥雙誰稅順說碩爍絲飼聳慫頌訟誦擻蘇訴肅雖綏歲孫損筍縮瑣鎖獺撻抬攤貪癱灘壇譚談歎湯燙濤滌騰謄銻題體屜條貼鐵廳聽烴銅統頭圖塗團頹蛻脫鴕馱駝橢窪襪彎灣頑萬網韋違圍為濰維葦偉偽緯謂衛溫聞紋穩問甕撾蝸渦窩嗚鎢烏誣無蕪吳塢霧務誤錫犧襲習銑戲細蝦轄峽俠狹廈掀鮮纖鹹賢銜閑顯險現獻縣餡羨憲線廂鑲鄉詳響項蕭銷曉嘯蠍協挾攜脅諧寫瀉謝鋅釁興洶鏽繡虛噓須許緒續軒懸選癬絢學勳詢尋馴訓訊遜壓鴉鴨啞亞訝閹煙鹽嚴顏閻豔厭硯彥諺驗鴦楊揚瘍陽癢養樣瑤搖堯遙窯謠藥爺頁業葉醫銥頤遺儀彝蟻藝億憶義詣議誼譯異繹蔭陰銀飲櫻嬰鷹應纓瑩螢營熒蠅穎喲擁傭癰踴詠湧優憂郵鈾猶遊誘輿魚漁娛與嶼語籲禦獄譽預馭鴛淵轅園員圓緣遠願約躍鑰嶽粵悅閱雲鄖勻隕運蘊醞暈韻雜災載攢暫贊贓髒鑿棗灶責擇則澤賊贈紮劄軋鍘閘詐齋債氈盞斬輾嶄棧戰綻張漲帳賬脹趙蟄轍鍺這貞針偵診鎮陣掙睜猙幀鄭證織職執紙摯擲幟質鍾終種腫眾謅軸皺晝驟豬諸誅燭矚囑貯鑄築駐專磚轉賺樁莊裝妝壯狀錐贅墜綴諄濁茲資漬蹤綜總縱鄒詛組鑽緻鐘麼為隻兇準啟闆裡靂餘鍊洩&#39;; } function Traditionalized(cc){ var str=&#39;&#39;,ss=JTPYStr(),tt=FTPYStr(); for(var i=0;i<cc.length;i++) { if(cc.charCodeAt(i)>10000&amp;&amp;ss.indexOf(cc.charAt(i))!=-1)str+=tt.charAt(ss.indexOf(cc.charAt(i))); else str+=cc.charAt(i); } return str; } function Simplized(cc){ var str=&#39;&#39;,ss=JTPYStr(),tt=FTPYStr(); for(var i=0;i<cc.length;i++) { if(cc.charCodeAt(i)>10000&amp;&amp;tt.indexOf(cc.charAt(i))!=-1)str+=ss.charAt(tt.indexOf(cc.charAt(i))); else str+=cc.charAt(i); } return str; } function setCookie(name, value) //cookies設置 { var argv = setCookie.arguments; var argc = setCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; if(expires!=null) { var LargeExpDate = new Date (); LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24)); } document.cookie = name + &#34;=&#34; + escape (value)+((expires == null) ? &#34;&#34; : (&#34;; expires=&#34; +LargeExpDate.toGMTString())); } function getCookie(Name) //cookies讀取 { var search = Name + &#34;=&#34; if(document.cookie.length > 0) { offset = document.cookie.indexOf(search) if(offset != -1) { offset += search.length end = document.cookie.indexOf(&#34;;&#34;, offset) if(end == -1) end = document.cookie.length return unescape(document.cookie.substring(offset, end)) } else return &#34;&#34; } } var StranLink_Obj=document.getElementById(&#34;StranLink&#34;) if (StranLink_Obj) { var JF_cn=&#34;ft&#34;+self.location.hostname.toString().replace(/\./g,&#34;&#34;) var BodyIsFt=getCookie(JF_cn) if(BodyIsFt!=&#34;1&#34;)BodyIsFt=Default_isFT with(StranLink_Obj) { if(typeof(document.all)!=&#34;object&#34;) //非IE瀏覽器 { href=&#34;javascript:StranBody()&#34; } else { href=&#34;#&#34;; onclick= new Function(&#34;StranBody();return false&#34;) } title=StranText(&#34;以繁體中文瀏覽&#34;,1,0) innerHTML=StranText(innerHTML,1,0) } if(BodyIsFt==&#34;1&#34;){setTimeout(&#34;StranBody()&#34;,StranIt_Delay)} } </script> </body> </html> [/code] ****************************************** 060118补 ****************************************** 限制textarea最大行数 [code]<textarea onpropertychange=&#34;var s=value.match(/\n/g);if(s)if(s.length>=10){alert(&#39;10行了&#39;);var str1=&#39;&#39;,str2=value.split(&#39;\n&#39;);for(i=0;i<10;i++){str1+=str2[i]}value=str1.substr(0,str1.length-1)}&#34; name=&#34;t&#34; rows=&#34;10&#34; cols=&#34;50&#34;></textarea> [/code] ///// 2006-02-08 新增 [code] function isNumber(str) { var ValidChars = &#34;0123456789.-&#34;; var err=0; if(str.length>20) return false; for (var i =0; i<str.length; i++) { if (ValidChars.indexOf(str.charAt(i)) == -1) { return false; } if (i==0&amp;&amp;((str.charAt(i)==&#39;0&#39;&amp;&amp;str.charAt(i)!=&#39;.&#39;)||str.charAt(i)==&#39;.&#39;)) { return false; } if (i!=0&amp;&amp;str.charAt(i)==&#39;-&#39;) { return false; } if (str.charAt(i)==&#39;.&#39;) { err++; if(err==2) return false; } } return true; } [/code] [code] function isPhone(str) { var valid = 1; var ValidChars = &#34;0123456789()-+ &#34;; if(str.length>20) valid=0; for (var i =0; valid!=0&amp;&amp;i < str.length; i++) { if (ValidChars.indexOf(str.charAt(i)) == -1) { valid = 0; } } return valid; } [/code] //严格的email格式判断 [code] function isEmailAddress(email) { invalidChars = &#34; /;,:{}[]|*%$#!()`<>?&#34;; if (email == &#34;&#34;) { return false; } for (i=0; i< invalidChars.length; i++) { badChar = invalidChars.charAt(i); if (email.indexOf(badChar,0) > -1) { return false; } } pos = email.indexOf(&#34;@&#34;,1) if (pos == -1) { return false; } if (email.indexOf(&#34;@&#34;, pos+1) != -1) { return false; } periodPos = email.indexOf(&#34;.&#34;,pos) if(periodPos == -1) { return false; } if ( pos + 2 > periodPos) { return false; } if ( periodPos + 3 > email.length) { return false; } return true; } [/code] //判断是否为网址,要求格式http://www.alibaba.com,是返回true,否返回false [code] function isWWW(str) { var reg=/^http:\/\/\S+\.\S+$/; return reg.test(str); } [/code] //判断是否为手机号码,要求11位数字,前二位为13,是返回true,否返回false [code] function isMobilePhone(str) { var reg=/^13\d{9}$/; return reg.test(str); } [/code] //判断是否为电话号码,要求格式0571-85022088,是返回true,否返回false [code] function isPhoneNum(str) { var reg=/^0\d{2,3}-\d{6,8}$/; return reg.test(str); } [/code] //判断是否是身份证号码 [code] function isPersonID(str) { if(isNumber(str) &amp;&amp; (str.length==15 || str.length==18)) { return true; } return false; } [/code] //判断是否为金额,要求格式最多2位小数,是返回true,否返回false [code] function isMoney(str) { var reg=/^\d+\.{0,1}\d{0,2}$/; return reg.test(str); } [/code] //判断是否为日期,要求格式2002-5-13或2002-05-13,是返回true,否返回false [code] function isDate(str) { var flag; //用正则表达式判断 var reg=/^\d{4}-\d{1,2}-\d{1,2}$/; flag=reg.test(str); if(flag==false) return flag; //判断日期是否正确 var YMD; YMD=str.split(&#34;-&#34;); var year,month,date; //年,月,日 year=parseInt(YMD[0]); month=parseInt(YMD[1]); date=parseInt(YMD[2]); if(month>12 || month<1) return false; if(date>31 || date<1) return false; var maxDate=new Array(12); //每月的最大日期 if(month==1) maxDate[0]=31; if(month==2) maxDate[1]=28; if(month==3) maxDate[2]=31; if(month==4) maxDate[3]=30; if(month==5) maxDate[4]=31; if(month==6) maxDate[5]=30; if(month==7) maxDate[6]=31; if(month==8) maxDate[7]=31; if(month==9) maxDate[8]=30; if(month==10) maxDate[9]=31; if(month==11) maxDate[10]=30; if(month==12) maxDate[11]=31; //闰月 if((year%4==0 &amp;&amp; year%100!=0) || (year%400==0)) maxDate[1]=29; if(maxDate[month-1]<date) return false; else return true; } [/code] //判断用户按键是否为数字 [code] function isNumPress() { if(window.event.keyCode>=48&amp;&amp;window.event.keyCode<=57) return true; else return false; } [/code] //判断用户按键是否为数字或回车 [code] function isNumOrEnterPress() { if((window.event.keyCode>=48 &amp;&amp; window.event.keyCode<=57) || window.event.keyCode==13) return true; else return false; } [/code] //字符串去除左右空格的方法 [code] function trim(str) { regExp1 = /^ */; regExp2 = / *$/; return str.replace(regExp1,&#39;&#39;).replace(regExp2,&#39;&#39;); } [/code] //显示问候语 [code] function showHello() { var greeting; var d = new Date(); h = d.getHours(); if(h<6) { greeting=&#34;凌晨好&#34;; } else if (h<9) { greeting=&#34;早上好&#34;; } else if (h<12) { greeting=&#34;上午好&#34;; } else if (h<14) { greeting=&#34;中午好&#34;; } else if (h<17) { greeting=&#34;下午好&#34;; } else if (h<19) { greeting=&#34;傍晚好&#34;; } else if (h<22) { greeting=&#34;晚上好&#34;; } else { greeting=&#34;夜里好&#34;; } document.write(greeting); } [/code] 是否有空字符1 [code] var whitespace = &#34; \t\n\r&#34;; function isWhitespace (s){ var i; if (isEmpty(s)) return true; for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (whitespace.indexOf(c) == -1) return false; } return true; } [/code] 是否有空字符2 [code] function hasWhitespace (s) { var i; for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (c == &#34; &#34;) { return true; } } return false; } [/code] //判断是否包含标点符号 [code] function hasInterpunction(s) { var i; for (i = 0; i < s.length; i++){ var c = s.charAt(i); if (c < &#34;0&#34;) { return true; } if (c > &#34;9&#34; &amp;&amp; c < &#34;A&#34;) { return true; } if (c > &#34;Z&#34; &amp;&amp; c < &#34;a&#34;) { return true; } if (c > &#34;z&#34; &amp;&amp; c <= &#34;~&#34;) { return true; } } return false; } [/code] [code] function isEmpty(s){ return ((s == null) || (s.length == 0)) } [/code] [code] function visibleField(_field,_hs){ if (document.all){ if(_hs == 1) eval(&#34;document.all.&#34;+_field +&#34;.style.visibility=&#39;visible&#39;;&#34;); if(_hs == 0) eval(&#34;document.all.&#34;+_field +&#34;.style.visibility=&#39;hidden&#39;;&#34;); }else{ if (_hs==&#39;1&#39;) eval(&#34;document.layers[&#39;&#34;+_field+&#34;&#39;].visibility=&#39;show&#39;;&#34;); if (_hs==&#39;0&#39;) eval(&#34;document.layers[&#39;&#34;+_field+&#34;&#39;].visibility=&#39;hide&#39;;&#34;); } } [/code] [code] function checkPhone (s){ var i; if (isEmpty(s)){ if (checkPhone.arguments.length == 1){ return false; }else{ return (checkPhone.arguments[1] == true); } } for (i = 0; i < s.length; i++){ var c = s.charAt(i); if(i == 0){ if(c == &#39;(&#39; ){ continue; } } else if( i == 4 ){ if(c == &#39;)&#39;){ continue; } } else if(i == 8){ if( c == &#39;-&#39;){ continue; } } else{ if (!isDigit(c)) return false; } } return true; } [/code] [code] function isInteger(getS){ var i; if (isEmpty(getS)) if (isInteger.arguments.length == 1) return false; else return (isInteger.arguments[1] == true); for (i = 0; i < getS.length; i++) { var c = getS.charAt(i); if (!isDigit(c)) return false; } return true; } [/code] 设置Cookie [code] function setCookie(name, value, expires, path, domain, secure) { var caution = false var curCookie = name + &#34;=&#34; + escape(value) + ((expires) ? &#34;; expires=&#34; + expires.toGMTString() : &#34;&#34;) + ((path) ? &#34;; path=&#34; + path : &#34;&#34;) + ((domain) ? &#34;; domain=&#34; + domain : &#34;&#34;) + ((secure) ? &#34;; secure&#34; : &#34;&#34;) if (!caution || (name + &#34;=&#34; + escape(value)).length <= 4000) document.cookie = curCookie else if (confirm(&#34;Cookie exceeds 4KB and will be cut!&#34;)) document.cookie = curCookie } [/code] [code] function getCookie(name) { var prefix = name + &#34;=&#34; var cookieStartIndex = document.cookie.indexOf(prefix) if (cookieStartIndex == -1) return null var cookieEndIndex = document.cookie.indexOf(&#34;;&#34;, cookieStartIndex + prefix.length) if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)) } [/code] [code] function del&#101;teCookie(name, path, domain) { if (getCookie(name)) { document.cookie = name + &#34;=&#34; + ((path) ? &#34;; path=&#34; + path : &#34;&#34;) + ((domain) ? &#34;; domain=&#34; + domain : &#34;&#34;) + &#34;; expires=Thu, 01-Jan-70 00:00:01 GMT&#34; } } [/code] [code] function encode(str) { var result = &#34;&#34;; for (i = 0; i < str.length; i++) { if (str.charAt(i) == &#34; &#34;) result += &#34;+&#34;; else if (str.charAt(i) == &#34; &#34;) result += &#34;+&#34;; else result += str.charAt(i); } return escape(result); } [/code] [code] function decode(str) { // var result = &#34;&#34;; var result = str.replace(/\+/g, &#34; &#34;); /* for (i = 0; i< str.length; i++) { if (str.charAt(i) == &#34;+&#34;) result += &#34; &#34;; else result += str.charAt(i); } */ return unescape(result); } [/code] [code] function encode1(str) { str = escape(str); return str.replace(/\+/g, &#34;%2B&#34;); } [/code] [code] function newwin(url) { var win = window.open(url,&#34;newwin&#34;,&#34;toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=620,height=600&#34;); win.focus(); } [/code] [code] function newupload(url) { var win = window.open(url,&#34;upload&#34;,&#34;toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,personal=no,menu=no,location=no,resizable=no,width=620,height=200&#34;); win.focus(); } [/code] [code] function doBlink() { // Blink, Blink, Blink... var blink = document.all.tags(&#34;BLINK&#34;) for (var i=0; i < blink.length; i++) blink[i].style.visibility = blink[i].style.visibility == &#34;&#34; ? &#34;hidden&#34; : &#34;&#34; } [/code] [code] function startBlink() { // Make sure it is IE4 if (document.all) setInterval(&#34;doBlink()&#34;,1000) } [/code] [code] function goback() { if(window.document.forms[1].Done) { window.location=window.document.forms[1].Done.value; } else if (window.document.forms[1].done) { window.location=window.document.forms[1].done.value; } else { history.go(-1) } } [/code] [code] function fullform() { var myform = document.forms[1]; for(var i=0;i<myform.elements.length;i++) { var element = myform.elements[i]; if (eval(&#34;typeof(&#34;+&#34;cgi_&#34;+element.name+&#34;)&#34;)==&#39;undefined&#39;) continue; var jsvar = eval(&#34;cgi_&#34;+element.name); if (element.type==&#34;sel&#101;ct-one&#34;) { for(var j=0;j<element.options.length;j++) { var option = element.options[j]; if (option.value==eval(&#34;cgi_&#34;+element.name)) { option.sel&#101;cted=true; break; } } } else if (element.type==&#34;text&#34;) { element.value=eval(&#34;cgi_&#34;+element.name); } else if (element.type==&#34;checkbox&#34;) { jsvar = jsvar+&#34;,&#34;; if (jsvar.indexOf(element.value+&#34;,&#34;)>-1) { element.checked=true; } } else if (element.type==&#34;radio&#34;) { if (jsvar==element.value) element.checked=true; } else if (element.type==&#34;textarea&#34;) { element.value=jsvar; } } } [/code] [code] function encode(url) { } //检查文本框字符长度(str文本框文本,minlen最小长度,maxlen最大长度) function checkSize(str, minlen, maxlen) { if(isEmpty(str)) { alert(&#34;内容为空 ^O^&#34;); return false; } else if(str.length < minlen || str.length > maxlen) { alert(&#34;请调节一下内容大小 ^&amp;^&#34;); return false; } } [/code] //长度为字符长度(不管单双字节) [code] function checkSize2(str, minlen, maxlen, objectName) { if(isEmpty(str)) { alert(&#34;“&#34; + objectName + &#34;”&#34; + &#34;内容为空 ^O^&#34;); return false; } else if(str.length < minlen || str.length > maxlen) { alert(&#34;请调节一下&#34; + &#34;“&#34; + objectName + &#34;”&#34; + &#34;内容大小 ^&amp;^&#34;); return false; } } [/code] [code] function getStrLength(str){ var length=0; for (var i = 0; i < str.length; i++) { var c = str.charCodeAt(i); if (c < 128){ length=length+1; }else{ length=length+2; } } return length; } [/code] 浏览器验证 [code]function checkBrowser() { this.ver=navigator.appVersion this.dom=document.getElementById?1:0 this.ie6=(this.ver.indexOf(&#34;MSIE 6&#34;)>-1 &amp;&amp; this.dom)?1:0; this.ie5=(this.ver.indexOf(&#34;MSIE 5&#34;)>-1 &amp;&amp; this.dom)?1:0; this.ie4=(document.all &amp;&amp; !this.dom)?1:0; this.ns5=(this.dom &amp;&amp; parseInt(this.ver) >= 5) ?1:0; this.ns4=(document.layers &amp;&amp; !this.dom)?1:0; this.mac=(this.ver.indexOf(&#39;Mac&#39;) > -1) ?1:0; this.ope=(navigator.userAgent.indexOf(&#39;Opera&#39;)>-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; } [/code]