.NET提升中...

No one will make you success to youself~

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
js经典代码 
  
2
  
31. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键 
  
4<table border oncontextmenu=return(false)><td>no</table> 可用于Table 
  
5
  
62<body onselectstart="return false"> 取消选取、防止复制 
  
7
  
83. onpaste="return false" 不准粘贴 
  
9
 
104. oncopy="return false;" oncut="return false;" 防止复制 
 
11
 
125<link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标 
 
13
 
146<link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标 
 
15
 
167<input style="ime-mode:disabled"> 关闭输入法 
 
17
 
188. 永远都会带着框架 
 
19<script language="javascript"><!-- 
 20
if (window == top)top.location.href = "frames.htm"//frames.htm为框架网页 
 21// --> 
 22
 
239. 防止被人frame 
 
24<SCRIPT LANGUAGE=javascript><!-- 
 25
if (top.location != self.location)top.location=self.location; 
 
26// --></SCRIPT> 
 27
 
2810. 网页将不能被另存为 
 
29<noscript><iframe src=*.html></iframe></noscript> 
 
30
 
3111<input type=button value=查看网页源代码 
 32onclick
="window.location = "view-source:""http://www.51js.com/""> 
 33
 
3412.删除时确认 
 
35<a href="javascript:if(confirm("确实要删除吗?")location="boos.asp?&areyou=删除&page=1"">删除</a> 
 
36
 
3713. 取得控件的绝对位置 
 
38//javascript 
 39<script language="javascript"> 
 40function getIE(e){ 
 41var t
=e.offsetTop; 
 42var l
=e.offsetLeft; 
 43
while(e=e.offsetParent){ 
 44t
+=e.offsetTop; 
 
45l+=e.offsetLeft; 
 
46
 47alert(
"top="+t+"/nleft="+l); 
 
48
 
49
 
50
 
51//VBScript 
 52<script language="VBScript"><!-- 
 53function getIE() 
 54dim t,l,a,b 
 55
set a=document.all.img1 
 56t
=document.all.img1.offsetTop 
 
57l=document.all.img1.offsetLeft 
 58
while a.tagName<>"BODY" 
 59
set a = a.offsetParent 
 60t
=t+a.offsetTop 
 
61l=l+a.offsetLeft 
 62wend 
 63msgbox 
"top="&t&chr(13)&"left="&l,64,"得到控件的位置" 
 64end function 
 
65--> 
 
66
 
6714. 光标是停在文本框文字的最后 
 
68<script language="javascript"> 
 69function cc() 
 
70
 71var e 
= event.srcElement; 
 72var r 
=e.createTextRange(); 
 73r.moveStart(
"character",e.value.length); 
 74r.collapse(
true); 
 75r.select(); 
 
76
 
77
 
78<input type=text name=text1 value="123" onfocus="cc()"> 
 
79
 
8015. 判断上一页的来源 
 81javascript: 
 82document.referrer 
 
83
 
8416. 最小化、最大化、关闭窗口 
 
85<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> 
 
86<param name="Command" value="Minimize"></object> 
 
87<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> 
 
88<param name="Command" value="Maximize"></object> 
 
89<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"> 
 
90<PARAM NAME="Command" VALUE="Close"></OBJECT> 
 
91
 
92<input type=button value=最小化 onclick=hh1.Click()> 
 
93<input type=button value=最大化 onclick=hh2.Click()> 
 
94<input type=button value=关闭 onclick=hh3.Click()> 
 95本例适用于IE 
 
96
 
9717.屏蔽功能键Shift,Alt,Ctrl 
 
98
 99function look(){ 
100
if(event.shiftKey) 
101alert(
"禁止按Shift键!"//可以换成ALT CTRL 
102
103document.onkeydown
=look; 
104
105
10618. 网页不会被缓存 
107<META HTTP-EQUIV="pragma" CONTENT="no-cache"> 
108<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"> 
109<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT"> 
110或者
<META HTTP-EQUIV="expires" CONTENT="0"> 
111
11219.怎样让表单没有凹凸感? 
113<input type=text style="border:1 solid #000000"> 
114或 
115<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom: 1 solid #000000"></textarea> 
116
11720.<div><span>&<layer>的区别? 
118<div>(division)用来定义大段的页面元素,会产生转行 
119<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行 
120<layer>是ns的标记,ie不支持,相当于<div> 
121
12221.让弹出窗口总是在最上面: 
123<body onblur="this.focus();"> 
124
12522.不要滚动条? 
126让竖条没有: 
127<body style="overflow:scroll;overflow-y:hidden"> 
128
129让横条没有: 
130<body style="overflow:scroll;overflow-x:hidden"> 
131
132两个都去掉?更简单了 
133<body scroll="no"> 
134
135
13623.怎样去掉图片链接点击后,图片周围的虚线? 
137<a href="#" onFocus="this.blur()"><img src="logo.jpg" border=0></a> 
138
13924.电子邮件处理提交表单 
140<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain"> 
141<input type=submit> 
142</form> 
143
14425.在打开的子窗口刷新父窗口的代码里如何写? 
145window.opener.location.reload() 
146
14726.如何设定打开页面的大小 
148<body onload="top.resizeTo(300,200);"> 
149打开页面的位置
<body onload="top.moveBy(300,200);"> 
150
15127.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动 
152<STYLE> 
153body 
154{background-image:url(logo.gif); background-repeat:no-repeat; background-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// --> 
163
16429. 获得一个窗口的大小 
165document.body.clientWidth; document.body.clientHeight 
166
16730. 怎么判断是否是字符 
168
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字"
169
else alert("全是字符"
170
17131.TEXTAREA自适应文字行数的多少 
172<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight"> 
173</textarea> 
174
17532. 日期减去天数等于第二个日期 
176<script language=javascript> 
177function cc(dd,dadd) 
178
179//可以加上错误处理 
180var a = new Date(dd) 
181a 
= a.valueOf() 
182a 
= a - dadd * 24 * 60 * 60 * 1000 
183a 
= new Date(a) 
184alert(a.getFullYear() 
+ "" + (a.getMonth() + 1+ "" + a.getDate() + "" 
185
186cc(
"12/23/2002",2
187
188
18933. 选择了哪一个Radio 
190<HTML><script language="vbscript"> 
191function checkme() 
192
for each ob in radio1 
193
if ob.checked then window.alert ob.value 
194next 
195end function 
196<BODY> 
197<INPUT name="radio1" type="radio" value="style" checked>Style 
198<INPUT name="radio1" type="radio" value="barcode">Barcode 
199<INPUT type="button" value="check" onclick="checkme()"> 
200</BODY></HTML> 
201
20234.脚本永不出错 
203<SCRIPT LANGUAGE="javascript"> 
204<!-- Hide 
205function killErrors() { 
206
return true
207
208window.onerror 
= killErrors; 
209// --> 
210</SCRIPT> 
211
21235.ENTER键可以让光标移到下一个输入框 
213<input onkeydown="if(event.keyCode==13)event.keyCode=9"> 
214
21536. 检测某个网站的链接速度: 
216把如下代码加入区域中: 
217<script language=javascript> 
218tim
=1 
219setInterval(
"tim++",100
220b
=1 
221
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" 
228
229function butt(){ 
230document.write(
"<form name=autof>" 
231
for(var i=1;i<autourl.length;i++
232document.write(
"<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO onclick=window.open(this.form.url"+i+".value)><br>" 
233document.write(
"<input type=submit value=刷新></form>" 
234
235butt() 
236function auto(url){ 
237document.forms[
0]["url"+b].value=url 
238
if(tim>200
239{document.forms[0]["txt"+b].value="链接超时"
240
else 
241{document.forms[0]["txt"+b].value="时间"+tim/10+""
242b
++ 
243
244function run(){
for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl+"/"+Math.random()+" width=1 height=1 onerror=auto("http://"+autourl+"" >"} 
245run() 
246
24737. 各种样式的光标 
248auto :标准光标 
249
default :标准箭头 
250hand :手形光标 
251wait :等待光标 
252text :I形光标 
253vertical
-text :水平I形光标 
254no
-drop :不可拖动光标 
255not
-allowed :无效光标 
256help :
?帮助光标 
257all
-scroll :三角方向标 
258move :移动标 
259crosshair :十字标 
260e
-resize 
261n
-resize 
262nw
-resize 
263w
-resize 
264s
-resize 
265se
-resize 
266sw
-resize 
267
26838.页面进入和退出的特效 
269进入页面
<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)"> 
270推出页面
<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)"> 
271这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1
-23
2720 矩形缩小 
2731 矩形扩大 
2742 圆形缩小 
2753 圆形扩大 
2764 下到上刷新 
2775 上到下刷新 
2786 左到右刷新 
2797 右到左刷新 
2808 竖百叶窗 
2819 横百叶窗 
28210 错位横百叶窗 
28311 错位竖百叶窗 
28412 点扩散 
28513 左右到中间刷新 
28614 中间到左右刷新 
28715 中间到上下 
28816 上下到中间 
28917 右下到左上 
29018 右上到左下 
29119 左上到右下 
29220 左下到右上 
29321 横条 
29422 竖条 
29523 以上22种随机选择一种 
296
29739.在规定时间内跳转 
298<META http-equiv=V="REFRESH" content="5;URL=http://www.51js.com"> 
299
30040.网页是否被检索 
301<meta name="ROBOTS" content="属性值"> 
302其中属性值有以下一些: 
303属性值为
"all": 文件将被检索,且页上链接可被查询; 
304属性值为
"none": 文件不被检索,而且不查询页上的链接; 
305属性值为
"index": 文件将被检索; 
306属性值为
"follow": 查询页上的链接; 
307属性值为
"noindex": 文件不检索,但可被查询链接; 
308属性值为
"nofollow": 文件不被检索,但可查询页上的链接。 
posted on 2007-08-03 16:24  叶自飘零  阅读(222)  评论(0编辑  收藏  举报