1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键
1<table border="" oncontextmenu="return(false)"><td>no</td></table>
可用于Table
2.
1<body onselectstart="return false"> 取消选取、防止复制
2
33\. onpaste="return false" 不准粘贴
4
54\. oncopy="return false;" oncut="return false;" 防止复制
6
75\. <link href="favicon.ico" rel="Shortcut Icon"/> IE地址栏前换成自己的图标
8
96\. <link href="favicon.ico" rel="Bookmark"/> 可以在收藏夹中显示出你的图标
10
117\. <input style="ime-mode:disabled"/> 关闭输入法
12
138\. 永远都会带着框架
14<script language="JavaScript"><!--
15if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
16// --></script>
17
189\. 防止被人frame
19<script language="JAVASCRIPT"><!--
20if (top.location != self.location)top.location=self.location;
21// --></script>
22
2310\. 网页将不能被另存为
24<noscript><iframe src="*.html"></iframe></noscript>
25
2611\. <input "http:="" onclick="window.location = " type="button" value="查看网页源代码" view-source:"+="" www.pconline.com.cn""=""/>
27
2812.删除时确认
29<a "="" href="javascript:if(confirm(" 确实要删除吗?"))location="boos.asp?&areyou=删除&page=1">删除</a>
30
3113\. 取得控件的绝对位置
32//Javascript
33<script language="Javascript">
34function getIE(e){
35var t=e.offsetTop;
36var l=e.offsetLeft;
37while(e=e.offsetParent){
38t+=e.offsetTop;
39l+=e.offsetLeft;
40}
41alert("top="+t+"/nleft="+l);
42}
43</script>
44
45//VBScript
46<script language="VBScript"><!--
47function getIE()
48dim t,l,a,b
49set a=document.all.img1
50t=document.all.img1.offsetTop
51l=document.all.img1.offsetLeft
52while a.tagName<>"BODY"
53set a = a.offsetParent
54t=t+a.offsetTop
55l=l+a.offsetLeft
56wend
57msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
58end function
59\--></script>
60
6114\. 光标是停在文本框文字的最后
62<script language="javascript">
63function cc()
64{
65var e = event.srcElement;
66var r =e.createTextRange();
67r.moveStart("character",e.value.length);
68r.collapse(true);
69r.select();
70}
71</script>
72<input name="text1" onfocus="cc()" type="text" value="123"/>
73
7415\. 判断上一页的来源
75javascript:
76document.referrer
77
7816\. 最小化、最大化、关闭窗口
79<object classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11" id="hh1">
80<param name="Command" value="Minimize"/></object>
81<object classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11" id="hh2">
82<param name="Command" value="Maximize"/></object>
83<object classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" id="hh3">
84<param name="Command" value="Close"/></object>
85<input onclick="hh1.Click()" type="button" value="最小化"/>
86<input onclick="hh2.Click()" type="button" value="最大化"/>
87<input onclick="hh3.Click()" type="button" value="关闭"/>
88本例适用于IE
89
90
9117.屏蔽功能键Shift,Alt,Ctrl
92<script>
93function look(){
94if(event.shiftKey)
95alert("禁止按Shift键!"); //可以换成ALT CTRL
96}
97document.onkeydown=look;
98</script>
99
10018\. 网页不会被缓存
101<meta content="no-cache" http-equiv="pragma"/>
102<meta content="no-cache, must-revalidate" http-equiv="Cache-Control"/>
103<meta content="Wed, 26 Feb 1997 08:21:57 GMT" http-equiv="expires"/>
104或者<meta content="0" http-equiv="expires"/>
105
10619.怎样让表单没有凹凸感?
107<input style="border:1 solid #000000" type="text"/>
108或
109<input style="border-left:none; border-right:none; border-top:none; border-bottom:
110
1111 solid #000000" type="text"/>
112
11320.<div><span>&<layer>的区别?
114<div>(division)用来定义大段的页面元素,会产生转行
115<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行
116<layer>是ns的标记,ie不支持,相当于<div>
117
118
119
120
12121.让弹出窗口总是在最上面:
122<body onblur="this.focus();">
123
12422.不要滚动条?
125让竖条没有:
126<body style="overflow:scroll;overflow-y:hidden">
127</body>
128让横条没有:
129<body style="overflow:scroll;overflow-x:hidden">
130</body>
131两个都去掉?更简单了
132<body scroll="no">
133</body>
134
13523.怎样去掉图片链接点击后,图片周围的虚线?
136<a href="#" onfocus="this.blur()"><img border="0" src="logo.jpg"/></a>
137
13824.电子邮件处理提交表单
139<form action=" mailto:****@***.com " enctype="text/plain" method="post" name="form1">
140<input type="submit"/>
141</form>
142
14325.在打开的子窗口刷新父窗口的代码里如何写?
144window.opener.location.reload()
145
14626.如何设定打开页面的大小
147<body onload="top.resizeTo(300,200);">
148打开页面的位置<body onload="top.moveBy(300,200);">
149
15027.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动
151<style>
152body
153{background-image:url(logo.gif); background-repeat:no-repeat;
154background-position:center;background-attachment: fixed}
155</style>
156
15728\. 检查一段字符串是否全由数字组成
158<script language="Javascript"><!--
159function checkNum(str){return str.match(//D/)==null}
160alert(checkNum("1232142141"))
161alert(checkNum("123214214a1"))
162// --></script>
163
16429\. 获得一个窗口的大小
165document.body.clientWidth; document.body.clientHeight
166
16730\. 怎么判断是否是字符
168if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
169else alert("全是字符");
170
17131.TEXTAREA自适应文字行数的多少
172<textarea cols="27" name="s1" onpropertychange="this.style.posHeight=this.scrollHeight" rows="1">
173</textarea>
174
175
17632\. 日期减去天数等于第二个日期
177<script language="Javascript">
178function cc(dd,dadd)
179{
180//可以加上错误处理
181var a = new Date(dd)
182a = a.valueOf()
183a = a - dadd * 24 * 60 * 60 * 1000
184a = new Date(a)
185alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
186}
187cc("12/23/2002",2)
188</script>
189
19033\. 选择了哪一个Radio
191<html><script language="vbscript">
192function checkme()
193for each ob in radio1
194if ob.checked then window.alert ob.value
195next
196end function
197</script><body>
198<input checked="" name="radio1" type="radio" value="style"/>Style
199<input name="radio1" type="radio" value="barcode"/>Barcode
200<input onclick="checkme()" type="button" value="check"/>
201</body></html>
202
20334.脚本永不出错
204<script language="JavaScript">
205<!-- Hide
206function killErrors() {
207return true;
208}
209window.onerror = killErrors;
210// -->
211</script>
212
21335.ENTER键可以让光标移到下一个输入框
214<input onkeydown="if(event.keyCode==13)event.keyCode=9"/>
215
21636\. 检测某个网站的链接速度:
217把如下代码加入<body>区域中:
218<script language="Javascript">
219tim=1
220setInterval("tim++",100)
221b=1
222var autourl=new Array()
223autourl[1]=" www.njcatv.net "
224autourl[2]="javacool.3322.net"
225autourl[3]=" www.sina.com.cn "
226autourl[4]=" www.nuaa.edu.cn "
227autourl[5]=" www.cctv.com "
228function butt(){
229document.write("<form name=autof>")
230for(var i=1;i<autourl.length;i++)
231document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text
232name=url"+i+" size=40> =》<input type=button value=GO
233
234onclick=window.open(this.form.url"+i+".value)><br>")
235document.write("<input type=submit value=刷新></form>")
236}
237butt()
238function auto(url){
239document.forms[0]["url"+b].value=url
240if(tim>200)
241{document.forms[0]["txt"+b].value="链接超时"}
242else
243{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}
244b++
245}
246function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl+"/"+Math.random()+" width=1 height=1
247
248onerror=auto(" http://"+autourl +"")>")}
249run()</script>
250
25137\. 各种样式的光标
252auto :标准光标
253default :标准箭头
254hand :手形光标
255wait :等待光标
256text :I形光标
257vertical-text :水平I形光标
258no-drop :不可拖动光标
259not-allowed :无效光标
260help :?帮助光标
261all-scroll :三角方向标
262move :移动标
263crosshair :十字标
264e-resize
265n-resize
266nw-resize
267w-resize
268s-resize
269se-resize
270sw-resize
271
272
27338.页面进入和退出的特效
274进入页面<meta content="revealTrans(duration=x, transition=y)" http-equiv="Page-Enter"/>
275推出页面<meta content="revealTrans(duration=x, transition=y)" http-equiv="Page-Exit"/>
276这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23:
2770 矩形缩小
2781 矩形扩大
2792 圆形缩小
2803 圆形扩大
2814 下到上刷新
2825 上到下刷新
2836 左到右刷新
2847 右到左刷新
2858 竖百叶窗
2869 横百叶窗
28710 错位横百叶窗
28811 错位竖百叶窗
28912 点扩散
29013 左右到中间刷新
29114 中间到左右刷新
29215 中间到上下
29316 上下到中间
29417 右下到左上
29518 右上到左下
29619 左上到右下
29720 左下到右上
29821 横条
29922 竖条
30023 以上22种随机选择一种
301
30239.在规定时间内跳转
303<meta content="5;URL=http://www.51js.com" http-equiv='V="REFRESH"'/>
304
30540.网页是否被检索
306<meta content="属性值" name="ROBOTS"/>
307其中属性值有以下一些:
308属性值为"all": 文件将被检索,且页上链接可被查询;
309属性值为"none": 文件不被检索,而且不查询页上的链接;
310属性值为"index": 文件将被检索;
311属性值为"follow": 查询页上的链接;
312属性值为"noindex": 文件不检索,但可被查询链接;
313属性值为"nofollow": 文件不被检索,但可查询页上的链接。</body></body></body></body></div></layer></div></span></div></layer></span></div></body>