1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键
M2mte#h <table border oncontextmenu=return(false)><td>no</table> 可用于Table
nKufVe 7pmhH%Dn$ 2. <body onselectstart="return false"> 取消选取、防止复制
A=E1S{C ~x`OCii 3. onpaste="return false" 不准粘贴
^P\(IDJCo F}.<x5I-;h 4. oncopy="return false;" oncut="return false;" 防止复制
hcwKi
h_Q9c 5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址栏前换成自己的图标
E_7N^htv RCo!sZP} 6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夹中显示出你的图标
GuNzrKDr B&`#`] 7. <input style="ime-mode:-Disabled"> 关闭输入法
EO3?Dev TU7 Qt< 8. 永远都会带着框架
hH|3s-o <script language="javascript"><!--
GR Rv0M if (window == top)top.location.href = "frames.htm"; //frames.htm为框架网页
?nCG:\&;'= // --></script>
+P81&CaY f9F@G&&Ugg 9. 防止被人frame
5fA<I _ D <SCRIPT LANGUAGE=javascript><!--
; Sq_DP1W if (top.location != self.location)top.location=self.location;
AWc7TW // --></SCRIPT>
:WJ[a# -]\UFR 10. 网页将不能被另存为
uL\ B[<: <noscript><iframe src=*.html></iframe></noscript>
VE6
V^6SL V*2uW2\} 11. <input type=button value=查看网页源代码
a4Fe MCvV9 onclick="window.location = `view-source:`+
http://www.51js.com/`";>
I_oJx oM M`7wJw 12.删除时确认
nM>oG'm[n <a href=`javascript:if(confirm("确实要删除吗?"location="boos.asp?&areyou=删除&page=1"`>删
OV_Y`u7YR nGZZCsf < 除</a>
yL7D;<!S& |^[]Oy= 13. 取得控件的绝对位置
cLEBcTx //javascript
hjtkq.@ <script language="javascript">
T;IaVMFG|d function getIE(E){
$0~H~- var t=e.offsetTop;
4RGEg;]S var l=e.offsetLeft;
rzsb( while(e=e.offsetParent){
bx_`S#*N t+=e.offsetTop;
?~Fk_#jz,@ l+=e.offsetLeft;
~k'KS
7c }
imv[xBA(d alert("top="+t+"/nleft="+l);
,`ST Va- }
UR>zL3 </script>
yZj:Kp+7 y1G Vn o //VBScript
FctqE/>}I <script language="VBScript"><!--
y-w=4_W function getIE()
GsA/pXx dim t,l,a,b
lTBPq?4{ set a=document.all.img1
7O^ySy"l t=document.all.img1.offsetTop
SV0E7qX l=document.all.img1.offsetLeft
xDD3Y{K while a.tagName<>"BODY"
hy3j8?66 set a = a.offsetParent
aVNBF` t=t+a.offsetTop
"7mYs)= l=l+a.offsetLeft
{7.."@Ob<v wend
?5_~Kn%2 msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
(LbAP9Zj#f end function
osPJ%I`^ --></script>
Cp` [0v~0 T[]2]K[&B 14. 光标是停在文本框文字的最后
;jS2bc:8a <script language="javascript">
SR7$m<0t* function cc()
[%7y !XD {
veIR)i@dx var e = event.srcElement;
5 0uYU[W var r =e.createTextRange();
+[Cdd{2 r.moveStart(`character`,e.value.length);
rH
Et]Xa r.collapse(true);
:iqFC >D r.select();
G5a PjP }
6;6a.iZ </script>
"Ah (EZAR
<input type=text name=text1 value="123" onfocus="cc()">
ARvT a$H*C(wL 15. 判断上一页的来源
Z
M_
6A1 javascript:
2[6>h) document.referrer
cVya~ * c@;$6WSG^ 16. 最小化、最大化、关闭窗口
})RT2zw} <object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
?@8[1$1a <param name="Command" value="Minimize"></object>
(WZKqt)S"o <object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
`]%\Y>(a} <param name="Command" value="Maximize"></object>
4gbi?UAmX <OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
[-C-+jC <PARAM NAME="Command" value="Close"></OBJECT>
uTgBnv(Y* acr@erk <input type=button value=最小化 onclick=hh1.Click()>
NsDJq{ <input type=button value=最大化 onclick=hh2.Click()>
`7_=2C <input type=button value=关闭 onclick=hh3.Click()>
9 f$S4O5 本例适用于IE
jR-DH]@y *qdf?'R 17.屏蔽功能键Shift,Alt,Ctrl
AE0d0Y~9 <script>
Hbwjs?Vq?] function look(){
]4~-
z3=y if(event.shiftKey)
,Fo7E alert("禁止按Shift键!"; //可以换成ALT CTRL
H^_]' ~. }
!_0kn6S5 document.onkeydown=look;
/xf4*zr </script>
m| 8%%E}d 4bXAA9" 18. 网页不会被缓存
BM PLL2I <META HTTP-EQUIV="pragma" CONTENT="no-cache">
`~|8eKFq! <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
HgL*/d <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
v\7k 或者<META HTTP-EQUIV="expires" CONTENT="0">
\;AW/&Ea D~ _|`D5WK 19.怎样让表单没有凹凸感?
.Rl58]x~ <input type=text style="border:1 solid #000000">
\bAsn89O 或
0=Jf93D5 <input type=text style="border-left:none; border-right:none; border-top:none; border-bottom:
"a;z $__e7 1 solid #000000"></textarea>
]}z;!D> K|*Cka{ 20.<div><span>&<layer>的区别?
Y#'mALC2 <div>(division)用来定义大段的页面元素,会产生转行
R:=C <span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行
pl62mp! <layer>是ns的标记,ie不支持,相当于<div>
pcw!e_"+ `< 8Fc`;[ 21.让弹出窗口总是在最上面:
,Nl]rmI <body onblur="this.focus();">
2{naSiaq UJ'
+Z6d 22.不要滚动条?
A6w/X`([O 让竖条没有:
%-"? <body style=`overflow:-Scroll;overflow-y:hidden`>
x h[4d </body>
w`XwW#!}@$ 让横条没有:
.&2p Z <body style=`overflow:-Scroll;overflow-x:hidden`>
/Z<" 6g? </body>
Ycb<'M*jE 两个都去掉?更简单了
!NuYx9L?L <body scroll="no">
w7\:S>;(O" </body>
v8g3]MVj3 qmUq9bV 23.怎样去掉图片链接点击后,图片周围的虚线?
rN#ydw:9 <a href="#" onFocus="this.blur()"><img src="logo.jpg" border=0></a>
K]dqK' :@g@jcbYq` 24.电子邮件处理提交表单
iqf+rBL <form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">
g3{)AX[Uy <input type=submit>
M52kau </form>
^EU&6M2 cn ,zUG!-h 25.在打开的子窗口刷新父窗口的代码里如何写?
WH :+HNl1d window.opener.location.reload()
p-V#nPb F= 26.如何设定打开页面的大小
:4$Ex2 <body onload="top.resizeTo(300,200);">
U@[P.y~J 打开页面的位置<body onload="top.moveBy(300,200);">
g-xbb&] &B3Eq1A 27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动
><iE VrpN <style>
gUDd2T# body
%o<&O(Y {background-image:url(logo.gif); background-repeat:no-repeat;
2a*1q#MpAt G}i\UXFE background-position:center;background-attachment: fixed}
Vja' :i </style>
E*Vx^k$ oMda)5 & 28. 检查一段字符串是否全由数字组成
#m
3WZ3t$ <script language="javascript"><!--
7-Rn{"5 function checkNum(str){return str.match(//D/)==null}
l1`Zp9I alert(checkNum("1232142141"
9BLz alert(checkNum("123214214a1"
4s*P5w_'/ // --></script>
Y">tfLIL_ 18w[T=7) 29. 获得一个窗口的大小
pPCxa#OV document.body.clientWidth; document.body.clientHeight
E=gD{1,? S6}_Z 30. 怎么判断是否是字符
n);2b\& if (/[^/x00-/xff]/g.test(s)) alert("含有汉字";
`u:U{m else alert("全是字符";
0<{/T*AU: O89<IXk 31.TEXTAREA自适应文字行数的多少
c}vy9m$B_ <textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
3@$h/xMJ </textarea>