常用的一些javascript小技巧
[from蓝色理想]
事件源对象
event.srcElement.tagName event.srcElement.type |
………………………………
常用的一些javascript小技巧
[from蓝色理想]
事件源对象
event.srcElement.tagName event.srcElement.type |
event.srcElement.setCapture(); event.srcElement.releaseCapture(); |
event.keyCode event.shiftKey event.altKey event.ctrlKey |
event.returnValue |
event.x event.y |
document.activeElement |
document.captureEvents(Event.KEYDOWN); |
document.all("txt").focus(); document.all("txt").select(); |
document.execCommand |
document.cookie |
document.oncontextmenu |
document.createElement("SPAN"); |
document.elementFromPoint(event.x,event.y).tagName=="TD document.elementFromPoint(event.x,event.y).appendChild(ms) |
document.images[索引] |
document.onmousedown=scrollwindow; |
document.窗体.elements[索引] |
navigator.plugins |
typeof($js_libpath) == "undefined" |
下拉框.options[索引] 下拉框.options.length |
document.getElementsByName("r1"); document.getElementById(id); |
escape() ,unescape |
obj.parentElement(dhtml) obj.parentNode(dom) |
TableID.moveRow(2,1) |
document.all.csss.href = "a.css"; |
display:inline |
hidefocus=true |
style="word-break:break-all" |
<meta HTTP-EQUIV="refresh" CONTENT="8;URL=http://c98.yeah.net"> |
<a href="mailto:[email protected]?subject=ccc&body=xxxyyy"> |
obj.scrollIntoView(true) |
<a name="first"> <a href="#first">anchors</a> |
location.search(); |
obj.contenteditable=true |
obj.execCommand |
/[^\x00-\xff]/ |
/[\u4e00-\u9fa5]/ |
word-wrap: break-word; word-break: break-all; |
<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe> |
obj.style.cssText |
document.documentElement.innerHTML |
document.styleSheets[0] |
document.styleSheets[0].rules[0] |
<a href="javascript:function()">word</a> |
asp: request.servervariables("HTTP_REFERER") javascript: document.referrer |
CollectGarbage(); |
document.oncontextmenu = function() { return false;} |
<noscript><iframe src="*.htm"></iframe></noscript> |
<body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty)" oncopy="document.selection.empty)" onbeforecopy= "return false"onmouseup="document.selection.empty()> |
<input type=text onpaste="return false"> |
<link rel="Shortcut Icon" href="favicon.ico"> favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下 收藏栏图标 <link rel="Bookmark" href="favicon.ico"> |
<input style="ime-mode:disabled"> |
<input type=text name=text1 value="123" onfocus="this.select()"> |
<input onkeydown="if(event.keyCode==13)event.keyCode=9"> |
<input type=text value="123" onfocus="alert(this.defaultValue)"> |
obj.title = "123 sdfs " |
var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime() |
win.closed |
<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"> |
document.selection.createRange().duplicate().text |
<input type=text autocomplete=on>打开该功能 <input type=text autocomplete=off>关闭该功能 |
<body onload="window.resizeTo(window.screen.width - 4,window.screen.height-50);window.moveTo(-4,-4)"> |
window.open("aa.htm", "meizz", "fullscreen=7"); |
alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe"))) encodeURIComponent对":"、"/"、";" 和 "?"也编码 |
s += "\r\n网页可见区域宽:"+ document.body.clientWidth; s += "\r\n网页可见区域高:"+ document.body.clientHeight; s += "\r\n网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)"; s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)"; s += "\r\n网页正文全文宽:"+ document.body.scrollWidth; s += "\r\n网页正文全文高:"+ document.body.scrollHeight; s += "\r\n网页被卷去的高:"+ document.body.scrollTop; s += "\r\n网页被卷去的左:"+ document.body.scrollLeft; s += "\r\n网页正文部分上:"+ window.screenTop; s += "\r\n网页正文部分左:"+ window.screenLeft; s += "\r\n屏幕分辨率的高:"+ window.screen.height; s += "\r\n屏幕分辨率的宽:"+ window.screen.width; s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight; s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth; |
//不缓存
<META HTTP-EQUIV="pragma" CONTENT="no-cache"> <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"> <META HTTP-EQUIV="expires" CONTENT="0"> |
匹配中文字符的正则表达式: [\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- ./?%&=]*)? |
oRect = obj.getBoundingClientRect(); oRect.left oRect. |
<p style="page-break-after:always">page1</p> <p style="page-break-after:always">page2</p> |
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="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object> <center class="Noprint" > <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> |
function modelessAlert(Msg) { window.showModelessDialog("javascript:alert(\""+escape(Msg)+"\");window.close();","","status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;"); } |
function DownURL(strRemoteURL,strLocalURL) { try { var xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP"); xmlHTTP.open("Get",strRemoteURL,false); xmlHTTP.send(); var adodbStream=new ActiveXObject("ADODB.Stream"); 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("下载URL出错!"); } //window.confirm("下载完成."); } |
function getXML(URL) { var xmlhttp = new ActiveXObject("microsoft.xmlhttp"); xmlhttp.Open("GET",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); } } } |
function CheckURL(URL) { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.Open("GET",URL, false); try { xmlhttp.Send(); var result = xmlhttp.status; } catch(e) {return(false); } if(result==200) { return true; } xmlhttp = null; return false; } |
1.注销组件 regsvr32 /u scrrun.dll 2.修改PROGID HKEY_CLASSES_ROOT\Scripting.FileSystemObject Scripting.FileSystemObject 3.对于使用object的用户,修改HKEY_CLASSES_ROOT\Scripting. |