201.将url转化为16进制形式 var ret = '';
for(var i=0; i < str.length; i++) { var ch = str.charAt(i); var code = str.charCodeAt(i);
if(code < 128 && ch != '[' && ch != '\'' && ch != '=') { ret += ch; } else { ret += "[" + code.toString(16) + "]"; } } return ret;//
202.打开新的窗口并将新打开的窗口设置为活动窗口 var newWin=window.open("xxxx"); newWin.focus();//
203.容错脚本 JS中遇到脚本错误时不做任何操作:window.onerror = doNothing; 指定错误句柄的语法为:window.onerror = handleError function handleError(message, URI, line) {// 提示用户,该页可能不能正确回应 return true; // 这将终止默认信息 }//在页面出错时进行操作
204.JS中的窗口重定向: window.navigate("http://www.sina.com.cn");//
205.防止链接文字折行 document.body.noWrap=true;//
206.判断字符是否匹配. string.match(regExpression)//
207. href="javascript:document.Form.Name.value='test';void(0);"//不能用onClick="javacript:document.Form.Name.v
alue='test';return false;"
当使用inline方式添加事件处理脚本事,有一个被包装成匿名函数的过程,也就是说 onClick="javacript:document.Form.Name.value='test';return false;"被包装成了: functoin anonymous() { document.Form.Name.value='test';return false; } 做为A的成员函数onclick。 而href="javascript:document.Form.Name.value='test';void(0);"相当于执行全局语句,这时如果使用return语句会
报告在函数外使用return语句的错误。
208.进行页面放大 <P onmouseover="this.style.zoom='200%'" onmouseout="this.style.zoom='normal'"> sdsdsdsdsdsdsdsds </p>//
209.放置在页面的最右边 <input type="text" value='bu2' style="float:right">//
210.通过style来控制隔行显示不同颜色 <style> tr{ bgcolor:expression(this.bgColor=((this.rowIndex)%2==0 )? 'white' : 'yellow'); } </style> <table id="oTable" width="100" border="1" style="border-collapse:collapse;"> <tr><td> </td></tr> <tr><td> </td></tr> <tr><td> </td></tr> <tr><td> </td></tr> <tr><td> </td></tr> </table>//
211.全屏最大化 newwindow=window.open("","","scrollbars") if (document.all) { newwindow.moveTo(0,0) newwindow.resizeTo(screen.width,screen.height) }//
212.根据名字解析xml中的节点值 var XMLDoc=new ActiveXObject("MSXML"); XMLDoc.url="d:/abc.xml"; aRoot=XMLDoc.root; a1.innerText=aRoot.children.item("name").text;//
213.在页面上解析xml的值 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08
fcccdf35.asp //
214.看一个字符串里面有多少个回车符,返回值是一个数组 var s=value.match(/\n/g);if(s)if(s.length==9){alert('10行了');return false;}//
215.获得asc码 var s='aa'; alert(s.charCodeAt(1))// 216.文字居右对齐 <input type="text" value="123" style="text-align:right">//
217.判断一个方法是否存在 function pageCallback(response){ alert(response); } if(pageCallback) alert(1)//
218.判断一个变量是否定义 if(typeof(a)=="undefined") { alert() }//
219.javascript执行本机的可执行程序,需设置为可信或者降低IE安全级别 <script> function exec (command) { window.oldOnError = window.onerror; window._command = command; window.onerror = function (err) { if (err.indexOf('utomation') != -1) { alert('命令已经被用户禁止!'); return true; } else return false; }; var wsh = new ActiveXObject('WScript.Shell'); if (wsh) wsh.Run(command); window.onerror = window.oldOnError; } </script> 调用方式 <a href="javascript:" onclick="exec('D:/test.bat')">测试</a>// 220.弹出新页面,关闭旧页面,不弹出提示框 var w=screen.availWidth-10; var h=screen.availHeight-10; var swin=window.open("/mc/mc/message_management.jsp",
"BGSMbest","scrollbars=yes,status,location=0,menubar=0,toolbar=0,resizable=no,top=0,left=0,height="+h+",w
idth="+w); window.opener=null; window.close();//
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1617 下一页
上一篇:Js之软键盘实现(源码) 下一篇:如何优化JavaScript脚本的性能
|