199.強制回應視窗父視窗var url="aaa.jsp";var data=showModalDialog(url,null,"dialogHeight:400px;dialogHeight:600px;center:yes;help:No;status:no;resizab le:Yes;edge:sunken");if(data) alert(data.value); 子視窗var data=new Object();data.value1="china";window.returnValue=data;window.close(); 200.動態設定事件,帶參數<INPUT TYPE="text" NAME="a1"><SCRIPT LANGUAGE="JavaScript"><!--function hah(para){ alert(para)}a1.onclick=function(){ hah('canshu ')}//a1.attachEvent("onclick",function(){hah('參數')});//--></SCRIPT>// 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 = handleErrorfunction 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的值 <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08</a> 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();// 221.能輸入的下拉框<span><input name="Department1" id="Department1" style=" border-right:0;width:130" autocomplete="off"><span style="width:150;overflow:hidden"><select style="width:150;margin-left:-130" onChange="Department1.value=value"><option value=""></option><option value="asdfasfadf">asdfasfadf</option><option value="546546">546546</option></select> // 222.在方法中定義全域變數function globalVar (script) { eval(script);//all navigators //window.execScript(script); //for ie only}globalVar('window.haha = "../system";');alert(haha);//在方法中定義全域變數,其中的haha就是全域變數了 223.顯示一個對象的全部的屬性和屬性的值var a=new Object();a.name='a1';a.***='mail'for(var p in a){ alert(p+"="+a[p])}// 224.16進位轉換成10進位var n = parseInt("2AE",16);//這裡將16進位的 2AE 轉成 10 進位數,得到 n 的值是 686 225.複製粘貼<BODY><input type="file" name='a1'><input type="button" value='複製粘貼' onclick="haha()"><div id="aa"></div><SCRIPT LANGUAGE="JavaScript"><!--function haha(){ clipboardData.setData("Text",a1.value); aa.innerText=clipboardData.getData("Text");}//--></SCRIPT></BODY>// 226.獲得物件類型switch (object.constructor){ case Date: ... case Number: ... case String: ... case MyObject: ... default: ...}// 227.圖片載入失敗時重新載入圖片<img src="aa.gif" onerror="this.src='aa.gif'">// 228.//font_effect.htc<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="glowit()" /><PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="noglow()" /><SCRIPT LANGUAGE="JScript">//定義一個儲存字型顏色的變數var color;function glowit(){ color=element.style.backgroundColor; element.style.backgroundColor='white'}function noglow(){ element.style.backgroundColor=color}</SCRIPT> //abc.csstr{behavior:url(font_effect.htc);} 229.可以通過css和htc改變表格的顏色,僅IE支援//xxx.html<link rel="stylesheet" type="text/css" href="abc.css"><TABLE border='1' id="a1"><TR style="background-color:red"> <TD>1</TD> <TD>2</TD> <TD>3</TD></TR><TR style="background-color:yellow"> <TD>4</TD> <TD>5</TD> <TD>6</TD></TR></TABLE>// 230.在頁面上畫點function a(x,y,color){ document.write("<img border='0' style='position: absolute; left: "+(x+20)+"; top: "+(y+20)+";background-color: "+color+"' width=1 height=1>")}// 231.自動關閉網頁<script LANGUAGE="javascript"><!--setTimeout('window.close();', 10000); //60秒後關閉// --></script><p align="center">本頁10秒後自動關閉,請注意重新整理頁面</p>