网站开发技巧参考大全
Code
1事件源对象
2event.srcElement.tagName
3event.srcElement.type
4捕获释放
5event.srcElement.setCapture();
6event.srcElement.releaseCapture();
7事件按键
8event.keyCode
9event.shiftKey
10event.altKey
11event.ctrlKey
12事件返回值
13event.returnValue
14鼠标位置
15event.x
16event.y
17窗体活动元素
18document.activeElement
19绑定事件
20document.captureEvents(Event.KEYDOWN);
21访问窗体元素
22document.all("txt").focus();
23document.all("txt").select();
24窗体命令
25document.execCommand
26窗体COOKIE
27document.cookie
28菜单事件
29document.oncontextmenu
30创建元素
31document.createElement("SPAN");
32根据鼠标获得元素:
33document.elementFromPoint(event.x,event.y).tagName=="TD
34document.elementFromPoint(event.x,event.y).appendChild(ms)
35窗体图片
36document.images[索引]
37窗体事件绑定
38document.onmousedown=scrollwindow;
39元素
40document.窗体.elements[索引]
41对象绑定事件
42document.all.xxx.detachEvent('onclick',a);
43插件数目
44navigator.plugins
45取变量类型
46typeof($js_libpath) == "undefined"
47下拉框
48下拉框.options[索引]
49下拉框.options.length
50查找对象
51document.getElementsByName("r1");
52document.getElementById(id);
53定时
54timer=setInterval('scrollwindow()',delay);
55clearInterval(timer);
56
57UNCODE编码
58escape() ,unescape
59
60父对象
61obj.parentElement(dhtml)
62obj.parentNode(dom)
63
64交换表的行
65TableID.moveRow(2,1)
66
67替换CSS
68document.all.csss.href = "a.css";
69
70并排显示
71display:inline
72
73隐藏焦点
74hidefocus=true
75
76根据宽度换行
77style="word-break:break-all"
78
79自动刷新
80<meta HTTP-EQUIV="refresh" C>
81
82简单邮件
83<a href="mailto:aaa@bbb.com?subject=ccc&body=xxxyyy">
84快速转到位置
85obj.scrollIntoView(true)
86
87锚
88<a name="first">
89<a href="#first">anchors</a>
90
91网页传递参数
92location.search();
93
94可编辑
95obj.contenteditable=true
96执行菜单命令
97obj.execCommand
98
99双字节字符
100/[^\x00-\xff]/
101汉字
102/[\u4e00-\u9fa5]/
103
104让英文字符串超出表格宽度自动换行
105word-wrap: break-word; word-break: break-all;
106透明背景
107<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>
108
109获得style内容
110obj.style.cssText
111
112HTML标签
113document.documentElement.innerHTML
114
115第一个style标签
116document.styleSheets[0]
117
118style标签里的第一个样式
119document.styleSheets[0].rules[0]
120
121防止点击空链接时,页面往往重置到页首端。
122<a href="javascriptunction()">word</a>
123上一网页源
124asp:
125request.servervariables("HTTP_REFERER")
126javascript:
127document.referrer
128释放内存
129CollectGarbage();
130
131禁止右键
132document.oncontextmenu = function() { return false;}
133禁止保存
134<noscript><iframe src="*.htm"></iframe></noscript>
135禁止选取<body oncontextmenu="return false" ondragstart="return false"
136onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()>
137
138禁止粘贴
139<input type=text >
140
141地址栏图标
142<link rel="Shortcut Icon" href="favicon.ico">
143favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
144
145收藏栏图标
146<link rel="Bookmark" href="favicon.ico">
147查看源码
148<input type=button value=查看网页源代码 >
149关闭输入法
150<input style="ime-modeisabled">
151自动全选
152<input type=text name=text1 value="123" >
153ENTER键可以让光标移到下一个输入框
154<input >
155
156文本框的默认值
157<input type=text value="123" >
158title换行
159obj.title = "123 sdfs "
160获得时间所代表的微秒
161var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
162
163窗口是否关闭
164win.closed
165checkbox扁平
166<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>
167
168获取选中内容
169document.selection.createRange().duplicate().text
170自动完成功能
171<input type=text autocomplete=on>打开该功能
172<input type=text autocomplete=off>关闭该功能
173窗口最大化
174<body >
175
176无关闭按钮IE
177window.open("aa.htm", "meizz", "fullscreen=7");
178统一编码/解码
179alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
180encodeURIComponent对":"、"/"、";" 和 "?"也编码
181表格行指示
182<tr >
183//各种尺寸
184s += "\r\n网页可见区域宽:"+ document.body.clientWidth;
185s += "\r\n网页可见区域高:"+ document.body.clientHeight;
186s += "\r\n网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)";
187s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
188s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;
189s += "\r\n网页正文全文高:"+ document.body.scrollHeight;
190s += "\r\n网页被卷去的高:"+ document.body.scrollTop;
191s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;
192s += "\r\n网页正文部分上:"+ window.screenTop;
193s += "\r\n网页正文部分左:"+ window.screenLeft;
194s += "\r\n屏幕分辨率的高:"+ window.screen.height;
195s += "\r\n屏幕分辨率的宽:"+ window.screen.width;
196s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;
197s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;
198
199//过滤数字
200<input type=text onkeypress="return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46alse)" onpaste="return !clipboardData.getData('text').match(/\D/)" ondragenter="return false">
201//特殊用途
202<input type=button value=导入收藏夹 onclick="window.external.ImportExportFavorites(true,'http://localhost');">
203<input type=button value=导出收藏夹 onclick="window.external.ImportExportFavorites(false,'http://localhost');">
204<input type=button value=整理收藏夹 onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)">
205<input type=button value=语言设置 onclick="window.external.ShowBrowserUI('LanguageDialog', null)">
206<input type=button value=加入收藏夹 onclick="window.external.AddFavorite('http://www.google.com/', 'google')">
207<input type=button value=加入到频道 onclick="window.external.addChannel('http://www.google.com/')">
208<input type=button value=加入到频道 onclick="window.external.showBrowserUI('PrivacySettings',null)">
209//不缓存
210<META HTTP-EQUIV="pragma" CONTENT="no-cache">
211<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
212<META HTTP-EQUIV="expires" CONTENT="0">
213
214//正则匹配
215匹配中文字符的正则表达式: [\u4e00-\u9fa5]
216匹配双字节字符(包括汉字在内):[^\x00-\xff]
217匹配空行的正则表达式:\n[\s| ]*\r
218匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/
219匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim函数)
220匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
221匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
222以下是例子:
223利用正则表达式限制网页表单里的文本框输入内容:
224用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"
2251.用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"
2262.用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
2273.用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
228//消除图像工具栏
229<IMG SRC="mypicture.jpg" HEIGHT="100px" WIDTH="100px" GALLERYIMG="false">
230or
231<head>
232<meta http-equiv="imagetoolbar" content="no">
233</head>
234//无提示关闭
235
236function Close()
237{
238var ua=navigator.userAgent
239var ie=navigator.appName=="Microsoft Internet Explorer"?truealse
240if(ie)
241{
242 var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
243 if(IEversion< 5.5)
244 {
245 var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
246 str += '<param name="Command" value="Close"></object>';
247 document.body.insertAdjacentHTML("beforeEnd", str);
248 document.all.noTipClose.Click();
249 }
250 else
251 {
252 window.opener =null;
253 window.close();
254 }
255 }
256else
257{
258 window.close()
259 }
260}
261//取得控件得绝对位置(1)
262
263<script language="javascript">
264function getoffset(e)
265{
266var t=e.offsetTop;
267var l=e.offsetLeft;
268while(e=e.offsetParent)
269{
270 t+=e.offsetTop;
271 l+=e.offsetLeft;
272}
273var rec = new Array(1);
274rec[0] = t;
275rec[1] = l;
276return rec
277}
278</script>
279//获得控件的绝对位置(2)
280oRect = obj.getBoundingClientRect();
281oRect.left
282oRect.
283//最小化,最大化,关闭
284<object id=min classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
285<param name="Command" value="Minimize"></object>
286<object id=max classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
287<param name="Command" value="Maximize"></object>
288<OBJECT id=close classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
289<PARAM NAME="Command" value="Close"></OBJECT>
290<input type=button value=最小化 onclick=min.Click()>
291<input type=button value=最大化 onclick=max.Click()>
292<input type=button value=关闭 onclick=close.Click()>
293
294
295
296
297//光标停在文字最后
298<script language="javascript">
299function cc()
300{
301var e = event.srcElement;
302var r =e.createTextRange();
303r.moveStart('character',e.value.length);
304r.collapse(true);
305r.select();
306}
307</script>
308<input type=text name=text1 value="123" onfocus="cc()">
309//页面进入和退出的特效
310
311进入页面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
312推出页面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">
313这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使
314用哪种特效,取值为1-23:
315 0 矩形缩小
316 1 矩形扩大
317 2 圆形缩小
318 3 圆形扩大
319 4 下到上刷新
320 5 上到下刷新
321 6 左到右刷新
322 7 右到左刷新
323 8 竖百叶窗
324 9 横百叶窗
325 10 错位横百叶窗
326 11 错位竖百叶窗
327 12 点扩散
328 13 左右到中间刷新
329 14 中间到左右刷新
330 15 中间到上下
331 16 上下到中间
332 17 右下到左上
333 18 右上到左下
334 19 左上到右下
335 20 左下到右上
336 21 横条
337 22 竖条
338 23
339//网页是否被检索
340<meta name="ROBOTS" content="属性值">
341 其中属性值有以下一些:
342 属性值为"all": 文件将被检索,且页上链接可被查询;
343 属性值为"none": 文件不被检索,而且不查询页上的链接;
344 属性值为"index": 文件将被检索;
345 属性值为"follow": 查询页上的链接;
346 属性值为"noindex": 文件不检索,但可被查询链接;
347 属性值为"nofollow":
348
349//打印分页
350<p style="page-break-after:always">page1</p>
351<p style="page-break-after:always">page2</p>
352
353//设置打印
354
355<object id="factory" style="display:none" viewastext
356 classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
357 codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"
358></object>
359<input type=button value=页面设置 onclick="factory.printing.PageSetup()">
360<input type=button value=打印预览 onclick="factory.printing.Preview()">
361
362<script language=javascript>
363function window.onload()
364{
365 // -- advanced features
366 factory.printing.SetMarginMeasure(2) // measure margins in inches
367 factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3
368 factory.printing.printer = "HP DeskJet 870C"
369 factory.printing.copies = 2
370 factory.printing.collate = true
371 factory.printing.paperSize = "A4"
372 factory.printing.paperSource = "Manual feed"
373 // -- basic features
374 factory.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页"
375 factory.printing.footer = "(自定义页脚)"
376 factory.printing.portrait = false
377 factory.printing.leftMargin = 0.75
378 factory.printing.topMargin = 1.5
379 factory.printing.rightMargin = 0.75
380 factory.printing.bottomMargin = 1.5
381}
382function Print(frame) {
383 factory.printing.Print(true, frame) // print with prompt
384}
385</script>
386<input type=button value="打印本页" onclick="factory.printing.Print(false)">
387<input type=button value="页面设置" onclick="factory.printing.PageSetup()">
388<input type=button value="打印预览" onclick="factory.printing.Preview()"><br>
389<a href="http://www.meadroid.com/scriptx/docs/printdoc.htm?static" target=_blank>具体使用手册,更多信息,点这里</a>
390
391//自带的打印预览
392WebBrowser.ExecWB(1,1) 打开
393Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
394Web.ExecWB(4,1) 保存网页
395Web.ExecWB(6,1) 打印
396Web.ExecWB(7,1) 打印预览
397Web.ExecWB(8,1) 打印页面设置
398Web.ExecWB(10,1) 查看页面属性
399Web.ExecWB(15,1) 好像是撤销,有待确认
400Web.ExecWB(17,1) 全选
401Web.ExecWB(22,1) 刷新
402Web.ExecWB(45,1) 关闭窗体无提示
403<style media=print>
404.Noprint{display:none;}<!--用本样式在打印时隐藏非打印项目-->
405.PageNext{page-break-after: always;}<!--控制分页-->
406</style>
407<object id="WebBrowser" width=0 height=0 classid="CLSID856F961-340A-11D0-A96B-00C04FD705A2">
408</object>
409
410<center class="Noprint" >
411<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
412<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
413<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
414</p>
415<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
416</center>
417//去掉打印时的页眉页脚
418
419<script language="JavaScript">
420var HKEY_Root,HKEY_Path,HKEY_Key;
421HKEY_Root="HKEY_CURRENT_USER";
422HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
423//设置网页打印的页眉页脚为空
424function PageSetup_Null()
425{
426try
427{
428 var Wsh=new ActiveXObject("WScript.Shell");
429 HKEY_Key="header";
430 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
431 HKEY_Key="footer";
432 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
433}
434catch(e){}
435}
436//设置网页打印的页眉页脚为默认值
437function PageSetup_Default()
438{
439try
440{
441 var Wsh=new ActiveXObject("WScript.Shell");
442 HKEY_Key="header";
443 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
444 HKEY_Key="footer";
445 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
446}
447catch(e){}
448}
449</script>
450<input type="button" value="清空页码" onclick=PageSetup_Null()>
451<input type="button" value="恢复页码" onclick=PageSetup_Default()>
452//浏览器验证
453
454function checkBrowser()
455{
456 this.ver=navigator.appVersion
457 this.dom=document.getElementById?1:0
458 this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
459 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
460 this.ie4=(document.all && !this.dom)?1:0;
461 this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
462 this.ns4=(document.layers && !this.dom)?1:0;
463 this.mac=(this.ver.indexOf('Mac') > -1) ?1:0;
464 this.ope=(navigator.userAgent.indexOf('Opera')>-1);
465 this.ie=(this.ie6 || this.ie5 || this.ie4)
466 this.ns=(this.ns4 || this.ns5)
467 this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac
468|| this.ope)
469 this.nbw=(!this.bw)
470 return this;
471}
472//计算内容宽和高
473<SCRIPT language="javascript">
474function test(obj)
475{
476 var range = obj.createTextRange();
477 alert("内容区宽度: " + range.boundingWidth
478 + "px\r\n内容区高度: " + range.boundingHeight + "px");
479
480}
481</SCRIPT>
482<BODY>
483<Textarea id="txt" height="150">sdf</textarea><INPUT type="button" value="计算内容宽度" onClick="test(txt)">
484</BODY>
485//无模式的提示框
486function modelessAlert(Msg)
487{
488 window.showModelessDialog("javascript:alert(\""+escape(Msg)+"\");window.close();","","status:no;resizable:no;help:no;
489dialogHeight:height:30px;dialogHeight:40px;");
490}
491
492//屏蔽按键
493<html>
494<head>
495 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
496 <noscript><meta http-equiv="refresh" content="0;url=about:noscript"></noscript>
497 <title>屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键</title>
498</head>
499<body>
500<script language="Javascript"><!--
501 //屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键
502 //Author: meizz(梅花雨) 2002-6-18
503function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键
504function window.onhelp(){return false} //屏蔽F1帮助
505function document.onkeydown()
506{
507 if ((window.event.altKey)&&
508 ((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ←
509 (window.event.keyCode==39))) //屏蔽 Alt+ 方向键 →
510 {
511 alert("不准你使用ALT+方向键前进或后退网页!");
512 event.returnValue=false;
513 }
514 /**//* 注:这还不是真正地屏蔽 Alt+ 方向键,
515 因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放,
516 用鼠标点掉警告框,这种屏蔽方法就失效了。以后若
517 有哪位高手有真正屏蔽 Alt 键的方法,请告知。*/
518 if ((event.keyCode==8) || //屏蔽退格删除键
519 (event.keyCode==116)|| //屏蔽 F5 刷新键
520 (event.ctrlKey && event.keyCode==82)){ //Ctrl + R
521 event.keyCode=0;
522 event.returnValue=false;
523 }
524 if (event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11
525 if (event.ctrlKey && event.keyCode==78) event.returnValue=false; //屏蔽 Ctrl+n
526 if (event.shiftKey && event.keyCode==121)event.returnValue=false; //屏蔽 shift+F10
527 if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
528 window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一网页
529 if ((window.event.altKey)&&(window.event.keyCode==115)) //屏蔽Alt+F4
530 {
531 window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
532 return false;
533 }
534}
535</script>
536屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键
537</body>
538</html>
539//屏蔽打印
540<style>
541@media print{
542* {display:none}
543}
544</style>
545//移动的图层,拖动
546
5471.<span style='position:absolute;width:200;height:200;background:red'
548onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>meizz</span>
549<script language=javascript>
550var Obj;
551function MouseDown(obj)
552{
553 Obj=obj;
554 Obj.setCapture();
555 Obj.l=event.x-Obj.style.pixelLeft;
556 Obj.t=event.y-Obj.style.pixelTop;
557}
558function MouseMove()
559{
560 if(Obj!=null)
561 {
562 Obj.style.left = event.x-Obj.l;
563 Obj.style.top = event.y-Obj.t;
564 }
565}
566function MouseUp()
567{
568 if(Obj!=null)
569 {
570 Obj.releaseCapture();
571 Obj=null;
572 }
573}
574</script>
5752.
576<div id="myDiv" src="logo.gif" ondrag="doDrag();" onmouseover="this.style.cursor='hand'"
577style="position:absolute;left=100;top=100;"
578onmousedown="doMouseDown();">
579<a href="#" onclick="return false"><h1>wlecome</h1></a>
580</div>
581<script language="JavaScript" type="text/javascript">
582var orgMouseX;
583var orgMouseY;
584var orgObjX;
585var orgObjY;
586function doDrag()
587{
588var myObject=document.all.myDiv;
589
590var x=event.clientX;
591var y=event.clientY;
592myObject.style.left=x-(orgMouseX-orgObjX);
593myObject.style.top=y-(orgMouseY-orgObjY);
594
595}
596function doMouseDown()
597{
598orgMouseX=event.clientX;
599orgMouseY=event.clientY;
600orgObjX=parseInt(document.all.myDiv.style.left);
601orgObjY=parseInt(document.all.myDiv.style.top);
602}
603
604</script>
605
606//文档状态改变
607
608<iframe src="a.html" id="f" name="f" scrolling="no" frameborder=0
609marginwidth=0 marginheight=0></iframe>
610<script>
611var doc=window.frames["f"].document;
612function s(){
613if (doc.readyState=="complete"){
614 document.all.f.style.height=doc.body.scrollHeight
615 document.all.f.style.width=doc.body.scrollWidth
616}
617}
618doc.onreadystatechange=s
619</script>
620
621
622//刷新后不变的文本框
623<HTML>
624<HEAD>
625<META NAME="save" CONTENT="history">
626<STYLE>
627 .sHistory {behavior:url(#default#savehistory);}
628</STYLE>
629</HEAD>
630<BODY>
631<INPUT class=sHistory type=text id=oPersistInput>
632</BODY>
633</HTML>
634//访问剪贴板
635(1)拖拽访问
636event.dataTransfer.setData("URL", oImage.src);
637sImageURL = event.dataTransfer.getData("URL")
638(2)普通访问
639window.clipboardData.setData("Text",oSource.innerText);
640window.clipboardData.getData("Text");
641
642
643
644
645
646
647Interop.SQLDMO.dll
648
649
650//操作COOKIE
651
652function SetCookie(sName, sValue)
653{
654document.cookie = sName + "=" + escape(sValue) + "; ";
655}
656function GetCookie(sName)
657{
658var aCookie = document.cookie.split("; ");
659for (var i=0; i < aCookie.length; i++)
660{
661
662 var aCrumb = aCookie.split("=");
663 if (sName == aCrumb[0])
664 return unescape(aCrumb[1]);
665}
666
667}
668function DelCookie(sName)
669{
670document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
671}
672//setTimeout增加参数
673<script>
674var _st = window.setTimeout;
675window.setTimeout = function(fRef, mDelay) {
676if(typeof fRef == 'function'){
677 var argu = Array.prototype.slice.call(arguments,2);
678 var f = (function(){ fRef.apply(null, argu); });
679 return _st(f, mDelay);
680}
681return _st(fRef,mDelay);
682}
683function test(x){
684alert(x);
685}
686window.setTimeout(test,1000,'fason');
687</script>
688
689//自定义的apply,call
690Function.prototype.apply = function (obj, argu) {
691if (obj) obj.constructor.prototype._caller = this;
692var argus = new Array();
693for (var i=0;i<argu.length;i++)
694 argus = "argu[" + i + "]";
695var r;
696eval("r = " + (obj ? ("obj._caller(" + argus.join(",") + ");") : ("this(" + argus.join(",") + ");")));
697return r;
698};
699Function.prototype.call = function (obj) {
700var argu = new Array();
701for (var i=1;i<arguments.length;i++)
702 argu[i-1] = arguments;
703return this.apply(obj, argu);
704};
705
706//下载文件
707function DownURL(strRemoteURL,strLocalURL)
708{
709try
710{
711 var xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");
712 xmlHTTP.open("Get",strRemoteURL,false);
713 xmlHTTP.send();
714 var adodbStream=new ActiveXObject("ADODB.Stream");
715 adodbStream.Type=1;//1=adTypeBinary
716 adodbStream.Open();
717 adodbStream.write(xmlHTTP.responseBody);
718 adodbStream.SaveToFile(strLocalURL,2);
719 adodbStream.Close();
720 adodbStream=null;
721 xmlHTTP=null;
722
723}
724catch(e)
725{
726 window.confirm("下载URL出错!");
727}
728//window.confirm("下载完成.");
729}
730
731//检验连接是否有效
732function getXML(URL)
733{
734var xmlhttp = new ActiveXObject("microsoft.xmlhttp");
735xmlhttp.Open("GET",URL, false);
736try
737{
738 xmlhttp.Send();
739}
740catch(e){}
741finally
742{
743 var result = xmlhttp.responseText;
744 if(result)
745 {
746 if(xmlhttp.Status==200)
747 {
748 return(true);
749 }
750 else
751 {
752 return(false);
753 }
754 }
755 else
756 {
757 return(false);
758 }
759}
760}
761//POST代替FORM
762<SCRIPT language="VBScript">
763Function URLEncoding(vstrIn)
764 strReturn = ""
765 For i = 1 To Len(vstrIn)
766 ThisChr = Mid(vStrIn,i,1)
767 If Abs(Asc(ThisChr)) < &HFF Then
768 strReturn = strReturn & ThisChr
769 Else
770 innerCode = Asc(ThisChr)
771 If innerCode < 0 Then
772 innerCode = innerCode + &H10000
773 End If
774 Hight8 = (innerCode And &HFF00)\ &HFF
775 Low8 = innerCode And &HFF
776 strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
777 End If
778 Next
779 URLEncoding = strReturn
780End Function
781Function bytes2BSTR(vIn)
782 strReturn = ""
783 For i = 1 To LenB(vIn)
784 ThisCharCode = AscB(MidB(vIn,i,1))
785 If ThisCharCode < &H80 Then
786 strReturn = strReturn & Chr(ThisCharCode)
787 Else
788 NextCharCode = AscB(MidB(vIn,i+1,1))
789 strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
790 i = i + 1
791 End If
792 Next
793 bytes2BSTR = strReturn
794End Function
795dim strA,oReq
796strA = URLEncoding("submit1=Submit&text1=中文")
797set oReq = CreateObject("MSXML2.XMLHTTP")
798oReq.open "POST","http://ServerName/VDir/TstResult.asp",false
799oReq.setRequestHeader "Content-Length",Len(strA)
800oReq.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
801oReq.send strA
802msgbox bytes2BSTR(oReq.responseBody)
803</SCRIPT>
804//readystate是xmlhttp返回数据的进度,0=载入中,1=未初始化,2=已载入,3=运行中,4=完成
805//组件是否安装
806isComponentInstalled("{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}", "componentID"))
807//检查网页是否存在
808
809function CheckURL(URL)
810{
811 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
812 xmlhttp.Open("GET",URL, false);
813 try
814 {
815 xmlhttp.Send();
816 var result = xmlhttp.status;
817 }
818 catch(e) {return(false); }
819 if(result==200)
820 {
821 return true;
822 }
823 xmlhttp = null;
824 return false;
825}
826//连接数据库
827
828<script language="javascript">
829 //用 JavaScript 写服务器端连接数据库的代码示例
830 var conn = new ActiveXObject("ADODB.Connection");
831 conn.Open("Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; "
832 +"Password=; Initial Catalog=pubs");
833 var rs = new ActiveXObject("ADODB.Recordset");
834 var sql="select * from authors";
835 rs.open(sql, conn);
836shtml = "<table width='100%' border=1>";
837shtml +="<tr bgcolor='#f4f4f4'><td>au_id</td><td>
838au_lname</td><td>au_fname
839</td><td>phone</td><td>address</td><td> city</td>
840<td>state</td><td>zip</td></tr>";
841 while(!rs.EOF)
842 {
843shtml += "<tr><td>" + rs("au_id") + "</td><td>" + rs("au_lname") + "</td><td>" + rs("au_fname") + "</td><td>" + rs("phone") + "</td><td>" + rs("address") + "</td><td>" + rs("city") + "</td><td>" + rs("state") + "</td><td>" + rs("zip") + "</td></tr>";
844rs.moveNext;
845 }
846 shtml += "</table>";
847 document.write(shtml);
848 rs.close();
849 rs = null;
850 conn.close();
851 conn = null;
852</script>
853//使用数据岛
854
855<html>
856<body>
857srno:<input type=text datasrc=#xmldate DataFLD=srno size="76"><BR>
858times:<input type=text datasrc=#xmldate DataFLD=times size="76"><BR>
859<input id="first" TYPE=button value="<< 第一条记录" onclick="xmldate.recordset.moveFirst()">
860<input id="prev" TYPE=button value="<上一条记录" onclick="xmldate.recordset.movePrevious()">
861<input id="next" TYPE=button value="下一条记录>" onclick="xmldate.recordset.moveNext()">
862<input id="last" TYPE=button value="最后一条记录>>" onclick="xmldate.recordset.moveLast()">
863<input id="Add" TYPE=button value="添加新记录" onclick="xmldate.recordset.addNew()">
864
865<XML ID="xmldate">
866<infolist>
867<info ><srno>20041025-01</srno><times>null</times></info>
868<info ><srno>20041101-09</srno><times>2004年10月1日2点22分0秒</times></info>
869</infolist>
870</XML>
871</body>
872</html>
873//获得参数
874<body>
875<a href="javascript:location.href=location.href + '?a=1&b=2'">search</a>
876<script language="JavaScript">
877<!--
878var a = location.search.substr(1);
879if(a.length>0)
880{
881var re = /([^&]*?)\=([^&]*)/g
882var s = a.match(re);
883for(var i= 0;i<s.length;i++)
884{
885 alert(s);
886 alert(s.split("=")[1]);
887}
888}
889//-->
890</script>
891</body>
892//可编辑SELECT
893<input type=text name=re_name style="width:100px;height:21px;font-size:10pt;"><span style="width:18px;border:0px solid red;"><select
894name="r00" style="margin-left:-100px;width:118px; background-colorFFEEEE;" onChange="document.all.re_name.value=this.value;">
895 <option value="1">11111111<option>
896 <option value="2">222222</option>
897 <option value="3">333333</option>
898 </select>
899 </span>
900
901
902
903
1事件源对象
2event.srcElement.tagName
3event.srcElement.type
4捕获释放
5event.srcElement.setCapture();
6event.srcElement.releaseCapture();
7事件按键
8event.keyCode
9event.shiftKey
10event.altKey
11event.ctrlKey
12事件返回值
13event.returnValue
14鼠标位置
15event.x
16event.y
17窗体活动元素
18document.activeElement
19绑定事件
20document.captureEvents(Event.KEYDOWN);
21访问窗体元素
22document.all("txt").focus();
23document.all("txt").select();
24窗体命令
25document.execCommand
26窗体COOKIE
27document.cookie
28菜单事件
29document.oncontextmenu
30创建元素
31document.createElement("SPAN");
32根据鼠标获得元素:
33document.elementFromPoint(event.x,event.y).tagName=="TD
34document.elementFromPoint(event.x,event.y).appendChild(ms)
35窗体图片
36document.images[索引]
37窗体事件绑定
38document.onmousedown=scrollwindow;
39元素
40document.窗体.elements[索引]
41对象绑定事件
42document.all.xxx.detachEvent('onclick',a);
43插件数目
44navigator.plugins
45取变量类型
46typeof($js_libpath) == "undefined"
47下拉框
48下拉框.options[索引]
49下拉框.options.length
50查找对象
51document.getElementsByName("r1");
52document.getElementById(id);
53定时
54timer=setInterval('scrollwindow()',delay);
55clearInterval(timer);
56
57UNCODE编码
58escape() ,unescape
59
60父对象
61obj.parentElement(dhtml)
62obj.parentNode(dom)
63
64交换表的行
65TableID.moveRow(2,1)
66
67替换CSS
68document.all.csss.href = "a.css";
69
70并排显示
71display:inline
72
73隐藏焦点
74hidefocus=true
75
76根据宽度换行
77style="word-break:break-all"
78
79自动刷新
80<meta HTTP-EQUIV="refresh" C>
81
82简单邮件
83<a href="mailto:aaa@bbb.com?subject=ccc&body=xxxyyy">
84快速转到位置
85obj.scrollIntoView(true)
86
87锚
88<a name="first">
89<a href="#first">anchors</a>
90
91网页传递参数
92location.search();
93
94可编辑
95obj.contenteditable=true
96执行菜单命令
97obj.execCommand
98
99双字节字符
100/[^\x00-\xff]/
101汉字
102/[\u4e00-\u9fa5]/
103
104让英文字符串超出表格宽度自动换行
105word-wrap: break-word; word-break: break-all;
106透明背景
107<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>
108
109获得style内容
110obj.style.cssText
111
112HTML标签
113document.documentElement.innerHTML
114
115第一个style标签
116document.styleSheets[0]
117
118style标签里的第一个样式
119document.styleSheets[0].rules[0]
120
121防止点击空链接时,页面往往重置到页首端。
122<a href="javascriptunction()">word</a>
123上一网页源
124asp:
125request.servervariables("HTTP_REFERER")
126javascript:
127document.referrer
128释放内存
129CollectGarbage();
130
131禁止右键
132document.oncontextmenu = function() { return false;}
133禁止保存
134<noscript><iframe src="*.htm"></iframe></noscript>
135禁止选取<body oncontextmenu="return false" ondragstart="return false"
136onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()>
137
138禁止粘贴
139<input type=text >
140
141地址栏图标
142<link rel="Shortcut Icon" href="favicon.ico">
143favicon.ico 名字最好不变16*16的16色,放虚拟目录根目录下
144
145收藏栏图标
146<link rel="Bookmark" href="favicon.ico">
147查看源码
148<input type=button value=查看网页源代码 >
149关闭输入法
150<input style="ime-modeisabled">
151自动全选
152<input type=text name=text1 value="123" >
153ENTER键可以让光标移到下一个输入框
154<input >
155
156文本框的默认值
157<input type=text value="123" >
158title换行
159obj.title = "123 sdfs "
160获得时间所代表的微秒
161var n1 = new Date("2004-10-10".replace(/-/g, "\/")).getTime()
162
163窗口是否关闭
164win.closed
165checkbox扁平
166<input type=checkbox style="position: absolute; clip:rect(5px 15px 15px 5px)"><br>
167
168获取选中内容
169document.selection.createRange().duplicate().text
170自动完成功能
171<input type=text autocomplete=on>打开该功能
172<input type=text autocomplete=off>关闭该功能
173窗口最大化
174<body >
175
176无关闭按钮IE
177window.open("aa.htm", "meizz", "fullscreen=7");
178统一编码/解码
179alert(decodeURIComponent(encodeURIComponent("http://你好.com?as= hehe")))
180encodeURIComponent对":"、"/"、";" 和 "?"也编码
181表格行指示
182<tr >
183//各种尺寸
184s += "\r\n网页可见区域宽:"+ document.body.clientWidth;
185s += "\r\n网页可见区域高:"+ document.body.clientHeight;
186s += "\r\n网页可见区域高:"+ document.body.offsetWeight +" (包括边线的宽)";
187s += "\r\n网页可见区域高:"+ document.body.offsetHeight +" (包括边线的宽)";
188s += "\r\n网页正文全文宽:"+ document.body.scrollWidth;
189s += "\r\n网页正文全文高:"+ document.body.scrollHeight;
190s += "\r\n网页被卷去的高:"+ document.body.scrollTop;
191s += "\r\n网页被卷去的左:"+ document.body.scrollLeft;
192s += "\r\n网页正文部分上:"+ window.screenTop;
193s += "\r\n网页正文部分左:"+ window.screenLeft;
194s += "\r\n屏幕分辨率的高:"+ window.screen.height;
195s += "\r\n屏幕分辨率的宽:"+ window.screen.width;
196s += "\r\n屏幕可用工作区高度:"+ window.screen.availHeight;
197s += "\r\n屏幕可用工作区宽度:"+ window.screen.availWidth;
198
199//过滤数字
200<input type=text onkeypress="return event.keyCode>=48&&event.keyCode<=57||(this.value.indexOf('.')<0?event.keyCode==46alse)" onpaste="return !clipboardData.getData('text').match(/\D/)" ondragenter="return false">
201//特殊用途
202<input type=button value=导入收藏夹 onclick="window.external.ImportExportFavorites(true,'http://localhost');">
203<input type=button value=导出收藏夹 onclick="window.external.ImportExportFavorites(false,'http://localhost');">
204<input type=button value=整理收藏夹 onclick="window.external.ShowBrowserUI('OrganizeFavorites', null)">
205<input type=button value=语言设置 onclick="window.external.ShowBrowserUI('LanguageDialog', null)">
206<input type=button value=加入收藏夹 onclick="window.external.AddFavorite('http://www.google.com/', 'google')">
207<input type=button value=加入到频道 onclick="window.external.addChannel('http://www.google.com/')">
208<input type=button value=加入到频道 onclick="window.external.showBrowserUI('PrivacySettings',null)">
209//不缓存
210<META HTTP-EQUIV="pragma" CONTENT="no-cache">
211<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
212<META HTTP-EQUIV="expires" CONTENT="0">
213
214//正则匹配
215匹配中文字符的正则表达式: [\u4e00-\u9fa5]
216匹配双字节字符(包括汉字在内):[^\x00-\xff]
217匹配空行的正则表达式:\n[\s| ]*\r
218匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/
219匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim函数)
220匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
221匹配网址URL的正则表达式:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
222以下是例子:
223利用正则表达式限制网页表单里的文本框输入内容:
224用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"
2251.用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"
2262.用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
2273.用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"
228//消除图像工具栏
229<IMG SRC="mypicture.jpg" HEIGHT="100px" WIDTH="100px" GALLERYIMG="false">
230or
231<head>
232<meta http-equiv="imagetoolbar" content="no">
233</head>
234//无提示关闭
235
236function Close()
237{
238var ua=navigator.userAgent
239var ie=navigator.appName=="Microsoft Internet Explorer"?truealse
240if(ie)
241{
242 var IEversion=parseFloat(ua.substring(ua.indexOf("MSIE ")+5,ua.indexOf(";",ua.indexOf("MSIE "))))
243 if(IEversion< 5.5)
244 {
245 var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
246 str += '<param name="Command" value="Close"></object>';
247 document.body.insertAdjacentHTML("beforeEnd", str);
248 document.all.noTipClose.Click();
249 }
250 else
251 {
252 window.opener =null;
253 window.close();
254 }
255 }
256else
257{
258 window.close()
259 }
260}
261//取得控件得绝对位置(1)
262
263<script language="javascript">
264function getoffset(e)
265{
266var t=e.offsetTop;
267var l=e.offsetLeft;
268while(e=e.offsetParent)
269{
270 t+=e.offsetTop;
271 l+=e.offsetLeft;
272}
273var rec = new Array(1);
274rec[0] = t;
275rec[1] = l;
276return rec
277}
278</script>
279//获得控件的绝对位置(2)
280oRect = obj.getBoundingClientRect();
281oRect.left
282oRect.
283//最小化,最大化,关闭
284<object id=min classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
285<param name="Command" value="Minimize"></object>
286<object id=max classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
287<param name="Command" value="Maximize"></object>
288<OBJECT id=close classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
289<PARAM NAME="Command" value="Close"></OBJECT>
290<input type=button value=最小化 onclick=min.Click()>
291<input type=button value=最大化 onclick=max.Click()>
292<input type=button value=关闭 onclick=close.Click()>
293
294
295
296
297//光标停在文字最后
298<script language="javascript">
299function cc()
300{
301var e = event.srcElement;
302var r =e.createTextRange();
303r.moveStart('character',e.value.length);
304r.collapse(true);
305r.select();
306}
307</script>
308<input type=text name=text1 value="123" onfocus="cc()">
309//页面进入和退出的特效
310
311进入页面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
312推出页面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">
313这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使
314用哪种特效,取值为1-23:
315 0 矩形缩小
316 1 矩形扩大
317 2 圆形缩小
318 3 圆形扩大
319 4 下到上刷新
320 5 上到下刷新
321 6 左到右刷新
322 7 右到左刷新
323 8 竖百叶窗
324 9 横百叶窗
325 10 错位横百叶窗
326 11 错位竖百叶窗
327 12 点扩散
328 13 左右到中间刷新
329 14 中间到左右刷新
330 15 中间到上下
331 16 上下到中间
332 17 右下到左上
333 18 右上到左下
334 19 左上到右下
335 20 左下到右上
336 21 横条
337 22 竖条
338 23
339//网页是否被检索
340<meta name="ROBOTS" content="属性值">
341 其中属性值有以下一些:
342 属性值为"all": 文件将被检索,且页上链接可被查询;
343 属性值为"none": 文件不被检索,而且不查询页上的链接;
344 属性值为"index": 文件将被检索;
345 属性值为"follow": 查询页上的链接;
346 属性值为"noindex": 文件不检索,但可被查询链接;
347 属性值为"nofollow":
348
349//打印分页
350<p style="page-break-after:always">page1</p>
351<p style="page-break-after:always">page2</p>
352
353//设置打印
354
355<object id="factory" style="display:none" viewastext
356 classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
357 codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"
358></object>
359<input type=button value=页面设置 onclick="factory.printing.PageSetup()">
360<input type=button value=打印预览 onclick="factory.printing.Preview()">
361
362<script language=javascript>
363function window.onload()
364{
365 // -- advanced features
366 factory.printing.SetMarginMeasure(2) // measure margins in inches
367 factory.printing.SetPageRange(false, 1, 3) // need pages from 1 to 3
368 factory.printing.printer = "HP DeskJet 870C"
369 factory.printing.copies = 2
370 factory.printing.collate = true
371 factory.printing.paperSize = "A4"
372 factory.printing.paperSource = "Manual feed"
373 // -- basic features
374 factory.printing.header = "居左显示&b居中显示&b居右显示页码,第&p页/共&P页"
375 factory.printing.footer = "(自定义页脚)"
376 factory.printing.portrait = false
377 factory.printing.leftMargin = 0.75
378 factory.printing.topMargin = 1.5
379 factory.printing.rightMargin = 0.75
380 factory.printing.bottomMargin = 1.5
381}
382function Print(frame) {
383 factory.printing.Print(true, frame) // print with prompt
384}
385</script>
386<input type=button value="打印本页" onclick="factory.printing.Print(false)">
387<input type=button value="页面设置" onclick="factory.printing.PageSetup()">
388<input type=button value="打印预览" onclick="factory.printing.Preview()"><br>
389<a href="http://www.meadroid.com/scriptx/docs/printdoc.htm?static" target=_blank>具体使用手册,更多信息,点这里</a>
390
391//自带的打印预览
392WebBrowser.ExecWB(1,1) 打开
393Web.ExecWB(2,1) 关闭现在所有的IE窗口,并打开一个新窗口
394Web.ExecWB(4,1) 保存网页
395Web.ExecWB(6,1) 打印
396Web.ExecWB(7,1) 打印预览
397Web.ExecWB(8,1) 打印页面设置
398Web.ExecWB(10,1) 查看页面属性
399Web.ExecWB(15,1) 好像是撤销,有待确认
400Web.ExecWB(17,1) 全选
401Web.ExecWB(22,1) 刷新
402Web.ExecWB(45,1) 关闭窗体无提示
403<style media=print>
404.Noprint{display:none;}<!--用本样式在打印时隐藏非打印项目-->
405.PageNext{page-break-after: always;}<!--控制分页-->
406</style>
407<object id="WebBrowser" width=0 height=0 classid="CLSID856F961-340A-11D0-A96B-00C04FD705A2">
408</object>
409
410<center class="Noprint" >
411<input type=button value=打印 onclick=document.all.WebBrowser.ExecWB(6,1)>
412<input type=button value=直接打印 onclick=document.all.WebBrowser.ExecWB(6,6)>
413<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
414</p>
415<p> <input type=button value=打印预览 onclick=document.all.WebBrowser.ExecWB(7,1)>
416</center>
417//去掉打印时的页眉页脚
418
419<script language="JavaScript">
420var HKEY_Root,HKEY_Path,HKEY_Key;
421HKEY_Root="HKEY_CURRENT_USER";
422HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
423//设置网页打印的页眉页脚为空
424function PageSetup_Null()
425{
426try
427{
428 var Wsh=new ActiveXObject("WScript.Shell");
429 HKEY_Key="header";
430 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
431 HKEY_Key="footer";
432 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
433}
434catch(e){}
435}
436//设置网页打印的页眉页脚为默认值
437function PageSetup_Default()
438{
439try
440{
441 var Wsh=new ActiveXObject("WScript.Shell");
442 HKEY_Key="header";
443 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
444 HKEY_Key="footer";
445 Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
446}
447catch(e){}
448}
449</script>
450<input type="button" value="清空页码" onclick=PageSetup_Null()>
451<input type="button" value="恢复页码" onclick=PageSetup_Default()>
452//浏览器验证
453
454function checkBrowser()
455{
456 this.ver=navigator.appVersion
457 this.dom=document.getElementById?1:0
458 this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
459 this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
460 this.ie4=(document.all && !this.dom)?1:0;
461 this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
462 this.ns4=(document.layers && !this.dom)?1:0;
463 this.mac=(this.ver.indexOf('Mac') > -1) ?1:0;
464 this.ope=(navigator.userAgent.indexOf('Opera')>-1);
465 this.ie=(this.ie6 || this.ie5 || this.ie4)
466 this.ns=(this.ns4 || this.ns5)
467 this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac
468|| this.ope)
469 this.nbw=(!this.bw)
470 return this;
471}
472//计算内容宽和高
473<SCRIPT language="javascript">
474function test(obj)
475{
476 var range = obj.createTextRange();
477 alert("内容区宽度: " + range.boundingWidth
478 + "px\r\n内容区高度: " + range.boundingHeight + "px");
479
480}
481</SCRIPT>
482<BODY>
483<Textarea id="txt" height="150">sdf</textarea><INPUT type="button" value="计算内容宽度" onClick="test(txt)">
484</BODY>
485//无模式的提示框
486function modelessAlert(Msg)
487{
488 window.showModelessDialog("javascript:alert(\""+escape(Msg)+"\");window.close();","","status:no;resizable:no;help:no;
489dialogHeight:height:30px;dialogHeight:40px;");
490}
491
492//屏蔽按键
493<html>
494<head>
495 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
496 <noscript><meta http-equiv="refresh" content="0;url=about:noscript"></noscript>
497 <title>屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键</title>
498</head>
499<body>
500<script language="Javascript"><!--
501 //屏蔽鼠标右键、Ctrl+N、Shift+F10、F11、F5刷新、退格键
502 //Author: meizz(梅花雨) 2002-6-18
503function document.oncontextmenu(){event.returnValue=false;}//屏蔽鼠标右键
504function window.onhelp(){return false} //屏蔽F1帮助
505function document.onkeydown()
506{
507 if ((window.event.altKey)&&
508 ((window.event.keyCode==37)|| //屏蔽 Alt+ 方向键 ←
509 (window.event.keyCode==39))) //屏蔽 Alt+ 方向键 →
510 {
511 alert("不准你使用ALT+方向键前进或后退网页!");
512 event.returnValue=false;
513 }
514 /**//* 注:这还不是真正地屏蔽 Alt+ 方向键,
515 因为 Alt+ 方向键弹出警告框时,按住 Alt 键不放,
516 用鼠标点掉警告框,这种屏蔽方法就失效了。以后若
517 有哪位高手有真正屏蔽 Alt 键的方法,请告知。*/
518 if ((event.keyCode==8) || //屏蔽退格删除键
519 (event.keyCode==116)|| //屏蔽 F5 刷新键
520 (event.ctrlKey && event.keyCode==82)){ //Ctrl + R
521 event.keyCode=0;
522 event.returnValue=false;
523 }
524 if (event.keyCode==122){event.keyCode=0;event.returnValue=false;} //屏蔽F11
525 if (event.ctrlKey && event.keyCode==78) event.returnValue=false; //屏蔽 Ctrl+n
526 if (event.shiftKey && event.keyCode==121)event.returnValue=false; //屏蔽 shift+F10
527 if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
528 window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一网页
529 if ((window.event.altKey)&&(window.event.keyCode==115)) //屏蔽Alt+F4
530 {
531 window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
532 return false;
533 }
534}
535</script>
536屏蔽鼠标右键、Ctrl+N、Shift+F10、Alt+F4、F11、F5刷新、退格键
537</body>
538</html>
539//屏蔽打印
540<style>
541@media print{
542* {display:none}
543}
544</style>
545//移动的图层,拖动
546
5471.<span style='position:absolute;width:200;height:200;background:red'
548onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>meizz</span>
549<script language=javascript>
550var Obj;
551function MouseDown(obj)
552{
553 Obj=obj;
554 Obj.setCapture();
555 Obj.l=event.x-Obj.style.pixelLeft;
556 Obj.t=event.y-Obj.style.pixelTop;
557}
558function MouseMove()
559{
560 if(Obj!=null)
561 {
562 Obj.style.left = event.x-Obj.l;
563 Obj.style.top = event.y-Obj.t;
564 }
565}
566function MouseUp()
567{
568 if(Obj!=null)
569 {
570 Obj.releaseCapture();
571 Obj=null;
572 }
573}
574</script>
5752.
576<div id="myDiv" src="logo.gif" ondrag="doDrag();" onmouseover="this.style.cursor='hand'"
577style="position:absolute;left=100;top=100;"
578onmousedown="doMouseDown();">
579<a href="#" onclick="return false"><h1>wlecome</h1></a>
580</div>
581<script language="JavaScript" type="text/javascript">
582var orgMouseX;
583var orgMouseY;
584var orgObjX;
585var orgObjY;
586function doDrag()
587{
588var myObject=document.all.myDiv;
589
590var x=event.clientX;
591var y=event.clientY;
592myObject.style.left=x-(orgMouseX-orgObjX);
593myObject.style.top=y-(orgMouseY-orgObjY);
594
595}
596function doMouseDown()
597{
598orgMouseX=event.clientX;
599orgMouseY=event.clientY;
600orgObjX=parseInt(document.all.myDiv.style.left);
601orgObjY=parseInt(document.all.myDiv.style.top);
602}
603
604</script>
605
606//文档状态改变
607
608<iframe src="a.html" id="f" name="f" scrolling="no" frameborder=0
609marginwidth=0 marginheight=0></iframe>
610<script>
611var doc=window.frames["f"].document;
612function s(){
613if (doc.readyState=="complete"){
614 document.all.f.style.height=doc.body.scrollHeight
615 document.all.f.style.width=doc.body.scrollWidth
616}
617}
618doc.onreadystatechange=s
619</script>
620
621
622//刷新后不变的文本框
623<HTML>
624<HEAD>
625<META NAME="save" CONTENT="history">
626<STYLE>
627 .sHistory {behavior:url(#default#savehistory);}
628</STYLE>
629</HEAD>
630<BODY>
631<INPUT class=sHistory type=text id=oPersistInput>
632</BODY>
633</HTML>
634//访问剪贴板
635(1)拖拽访问
636event.dataTransfer.setData("URL", oImage.src);
637sImageURL = event.dataTransfer.getData("URL")
638(2)普通访问
639window.clipboardData.setData("Text",oSource.innerText);
640window.clipboardData.getData("Text");
641
642
643
644
645
646
647Interop.SQLDMO.dll
648
649
650//操作COOKIE
651
652function SetCookie(sName, sValue)
653{
654document.cookie = sName + "=" + escape(sValue) + "; ";
655}
656function GetCookie(sName)
657{
658var aCookie = document.cookie.split("; ");
659for (var i=0; i < aCookie.length; i++)
660{
661
662 var aCrumb = aCookie.split("=");
663 if (sName == aCrumb[0])
664 return unescape(aCrumb[1]);
665}
666
667}
668function DelCookie(sName)
669{
670document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
671}
672//setTimeout增加参数
673<script>
674var _st = window.setTimeout;
675window.setTimeout = function(fRef, mDelay) {
676if(typeof fRef == 'function'){
677 var argu = Array.prototype.slice.call(arguments,2);
678 var f = (function(){ fRef.apply(null, argu); });
679 return _st(f, mDelay);
680}
681return _st(fRef,mDelay);
682}
683function test(x){
684alert(x);
685}
686window.setTimeout(test,1000,'fason');
687</script>
688
689//自定义的apply,call
690Function.prototype.apply = function (obj, argu) {
691if (obj) obj.constructor.prototype._caller = this;
692var argus = new Array();
693for (var i=0;i<argu.length;i++)
694 argus = "argu[" + i + "]";
695var r;
696eval("r = " + (obj ? ("obj._caller(" + argus.join(",") + ");") : ("this(" + argus.join(",") + ");")));
697return r;
698};
699Function.prototype.call = function (obj) {
700var argu = new Array();
701for (var i=1;i<arguments.length;i++)
702 argu[i-1] = arguments;
703return this.apply(obj, argu);
704};
705
706//下载文件
707function DownURL(strRemoteURL,strLocalURL)
708{
709try
710{
711 var xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");
712 xmlHTTP.open("Get",strRemoteURL,false);
713 xmlHTTP.send();
714 var adodbStream=new ActiveXObject("ADODB.Stream");
715 adodbStream.Type=1;//1=adTypeBinary
716 adodbStream.Open();
717 adodbStream.write(xmlHTTP.responseBody);
718 adodbStream.SaveToFile(strLocalURL,2);
719 adodbStream.Close();
720 adodbStream=null;
721 xmlHTTP=null;
722
723}
724catch(e)
725{
726 window.confirm("下载URL出错!");
727}
728//window.confirm("下载完成.");
729}
730
731//检验连接是否有效
732function getXML(URL)
733{
734var xmlhttp = new ActiveXObject("microsoft.xmlhttp");
735xmlhttp.Open("GET",URL, false);
736try
737{
738 xmlhttp.Send();
739}
740catch(e){}
741finally
742{
743 var result = xmlhttp.responseText;
744 if(result)
745 {
746 if(xmlhttp.Status==200)
747 {
748 return(true);
749 }
750 else
751 {
752 return(false);
753 }
754 }
755 else
756 {
757 return(false);
758 }
759}
760}
761//POST代替FORM
762<SCRIPT language="VBScript">
763Function URLEncoding(vstrIn)
764 strReturn = ""
765 For i = 1 To Len(vstrIn)
766 ThisChr = Mid(vStrIn,i,1)
767 If Abs(Asc(ThisChr)) < &HFF Then
768 strReturn = strReturn & ThisChr
769 Else
770 innerCode = Asc(ThisChr)
771 If innerCode < 0 Then
772 innerCode = innerCode + &H10000
773 End If
774 Hight8 = (innerCode And &HFF00)\ &HFF
775 Low8 = innerCode And &HFF
776 strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
777 End If
778 Next
779 URLEncoding = strReturn
780End Function
781Function bytes2BSTR(vIn)
782 strReturn = ""
783 For i = 1 To LenB(vIn)
784 ThisCharCode = AscB(MidB(vIn,i,1))
785 If ThisCharCode < &H80 Then
786 strReturn = strReturn & Chr(ThisCharCode)
787 Else
788 NextCharCode = AscB(MidB(vIn,i+1,1))
789 strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
790 i = i + 1
791 End If
792 Next
793 bytes2BSTR = strReturn
794End Function
795dim strA,oReq
796strA = URLEncoding("submit1=Submit&text1=中文")
797set oReq = CreateObject("MSXML2.XMLHTTP")
798oReq.open "POST","http://ServerName/VDir/TstResult.asp",false
799oReq.setRequestHeader "Content-Length",Len(strA)
800oReq.setRequestHeader "CONTENT-TYPE","application/x-www-form-urlencoded"
801oReq.send strA
802msgbox bytes2BSTR(oReq.responseBody)
803</SCRIPT>
804//readystate是xmlhttp返回数据的进度,0=载入中,1=未初始化,2=已载入,3=运行中,4=完成
805//组件是否安装
806isComponentInstalled("{6B053A4B-A7EC-4D3D-4567-B8FF8A1A5739}", "componentID"))
807//检查网页是否存在
808
809function CheckURL(URL)
810{
811 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
812 xmlhttp.Open("GET",URL, false);
813 try
814 {
815 xmlhttp.Send();
816 var result = xmlhttp.status;
817 }
818 catch(e) {return(false); }
819 if(result==200)
820 {
821 return true;
822 }
823 xmlhttp = null;
824 return false;
825}
826//连接数据库
827
828<script language="javascript">
829 //用 JavaScript 写服务器端连接数据库的代码示例
830 var conn = new ActiveXObject("ADODB.Connection");
831 conn.Open("Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; "
832 +"Password=; Initial Catalog=pubs");
833 var rs = new ActiveXObject("ADODB.Recordset");
834 var sql="select * from authors";
835 rs.open(sql, conn);
836shtml = "<table width='100%' border=1>";
837shtml +="<tr bgcolor='#f4f4f4'><td>au_id</td><td>
838au_lname</td><td>au_fname
839</td><td>phone</td><td>address</td><td> city</td>
840<td>state</td><td>zip</td></tr>";
841 while(!rs.EOF)
842 {
843shtml += "<tr><td>" + rs("au_id") + "</td><td>" + rs("au_lname") + "</td><td>" + rs("au_fname") + "</td><td>" + rs("phone") + "</td><td>" + rs("address") + "</td><td>" + rs("city") + "</td><td>" + rs("state") + "</td><td>" + rs("zip") + "</td></tr>";
844rs.moveNext;
845 }
846 shtml += "</table>";
847 document.write(shtml);
848 rs.close();
849 rs = null;
850 conn.close();
851 conn = null;
852</script>
853//使用数据岛
854
855<html>
856<body>
857srno:<input type=text datasrc=#xmldate DataFLD=srno size="76"><BR>
858times:<input type=text datasrc=#xmldate DataFLD=times size="76"><BR>
859<input id="first" TYPE=button value="<< 第一条记录" onclick="xmldate.recordset.moveFirst()">
860<input id="prev" TYPE=button value="<上一条记录" onclick="xmldate.recordset.movePrevious()">
861<input id="next" TYPE=button value="下一条记录>" onclick="xmldate.recordset.moveNext()">
862<input id="last" TYPE=button value="最后一条记录>>" onclick="xmldate.recordset.moveLast()">
863<input id="Add" TYPE=button value="添加新记录" onclick="xmldate.recordset.addNew()">
864
865<XML ID="xmldate">
866<infolist>
867<info ><srno>20041025-01</srno><times>null</times></info>
868<info ><srno>20041101-09</srno><times>2004年10月1日2点22分0秒</times></info>
869</infolist>
870</XML>
871</body>
872</html>
873//获得参数
874<body>
875<a href="javascript:location.href=location.href + '?a=1&b=2'">search</a>
876<script language="JavaScript">
877<!--
878var a = location.search.substr(1);
879if(a.length>0)
880{
881var re = /([^&]*?)\=([^&]*)/g
882var s = a.match(re);
883for(var i= 0;i<s.length;i++)
884{
885 alert(s);
886 alert(s.split("=")[1]);
887}
888}
889//-->
890</script>
891</body>
892//可编辑SELECT
893<input type=text name=re_name style="width:100px;height:21px;font-size:10pt;"><span style="width:18px;border:0px solid red;"><select
894name="r00" style="margin-left:-100px;width:118px; background-colorFFEEEE;" onChange="document.all.re_name.value=this.value;">
895 <option value="1">11111111<option>
896 <option value="2">222222</option>
897 <option value="3">333333</option>
898 </select>
899 </span>
900
901
902
903