网页常用小技巧

上一篇 / 下一篇  2007-06-09 08:34:06 / 个人分类:网页知识

2007-06-01 14:34:46 / 个人分类:javascrīpt

1.oncontextmenu="window.event.returnValue=false"将彻底屏蔽鼠标右键51Testing软件测试网{ u JDA7MQ
  <table border ōncontextmenu=return(false)><td>no</table>可用于Table

2.<body ōnselectstart="return false">取消选取、防止复制

3.onpaste="return false"不准粘贴

4.oncopy="return false;" ōncut="return false;"防止复制

5.<link rel="Shortcut Icon" href="favicion.ico">IE地址栏前换成自己的图标

6.<link rel="Bookmark" href="favicion.ico">可以在收藏夹中显示出你的图标

7.<input style="ime-mode:disabled">关闭输入法

8.永远都会带着框架
.C"rO&j ]EB65703<scrīpt language="Javascrīpt">51Testing软件测试网)})g#h$T'Y \ S A4]z
<!--51Testing软件测试网u`!q7s Vu&[f
if(window==top)top.location.href="frams.htm";//frames.htm为框架网页51Testing软件测试网 L g;ek^Rv`M
//--></scrīpt>

9.防止被人frame
%VQR.y5eDx7v"U#s65703<scrīpt language=javascrīpt>51Testing软件测试网r0wb,t2o.n9m$m
<!--
YT[ C _b5s.p!E;_65703if(top.location!=self.location)top.location=self.location;
#N+h sg P CGU65703-->
pW"hZ?f k"R65703</scrīpt>

10.网页将不能被另存为51Testing软件测试网(}2bs `~ F
<noscrīpt><iframe src=*.html><iframe></noscrīpt>

11.<input type=button value=查看网页源代码 ōnclick="window.location="view-source:"+http://www.51.js.com/">

12.删除时确认
+O2B"dC,m4Rt9@65703<a href="javascrīpt:if(confirm("确实要删除吗?"))location="boos.asp?&areyou=删除&page=1"">删除</a>

13. 取得控件的绝对位置51Testing软件测试网&ur7YlHqt
//Javascrīpt
3C3E&H2^[x"V%t65703<scrīpt language="Javascrīpt">
Xjx}0f1i65703function getIE(e){51Testing软件测试网+_ wis$x/Pf4s?!l
var t=e.offsetTop;
v(I2a+RKf;k'd@@65703var l=e.offsetLeft;51Testing软件测试网q(g2H"|-z*CGF \
while(e=e.offsetParent){
o u$E4f5O65703t+=e.offsetTop;51Testing软件测试网*Z!L)w#H ZAR
l+=e.offsetLeft;
/v/},k&e}F ~5k r65703}
T+yq.x0H5@.C(i:W%q65703alert("top="+t+"/nleft="+l);
f#U ~z }Syc65703}51Testing软件测试网xbuH+_#j,a/I?
</scrīpt>

//VBscrīpt51Testing软件测试网7bPt.q|
<scrīpt language="VBscrīpt"><!--
B7M\|b/g:[y2x65703function getIE()
6l)_ pw9S65703dim t,l,a,b
x%_6KBX)|65703set a=document.all.img1
3B0s9G EP-V65703t=document.all.img1.offsetTop51Testing软件测试网5A+o ~];tu5S
l=document.all.img1.offsetLeft51Testing软件测试网*usw U~km
while a.tagName<>"BODY"
l ``SQ3A8nB65703set a = a.offsetParent51Testing软件测试网L e/Li Dhsd
t=t+a.offsetTop
1p#g*br2T![1M$T+D65703l=l+a.offsetLeft
q-cJb0X y+LZ65703wend
y} wwHk0DK65703msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"51Testing软件测试网)S YkY w }'bu6g$j
end function
/I c_-T,fxmI65703--></scrīpt>

14. 光标是停在文本框文字的最后
Be-zi7S0w3`65703<scrīpt language="javascrīpt">
r/Z1h$X~t7hc65703function cc()
3T&Bw9B g3K D#`5W)X"m },t65703{51Testing软件测试网,fJ~:OF2}eH
var e = event.srcElement;
ykU9B0~(a&{Z5B65703var r =e.createTextRange();51Testing软件测试网3?!CEB3g Hd"P*Y(g
r.moveStart("character",e.value.length);
%Hxwg#r`|:?gL6K65703r.collapse(true);51Testing软件测试网a2h}5Y9p3?n
r.select();
@-gW8`o*Wl65703}51Testing软件测试网3MTx {4^,o;X*o S.|
</scrīpt>51Testing软件测试网;}W8fvb!Q2N
<input type=text name=text1 value="123" ōnfocus="cc()">

15. 判断上一页的来源
-bN Qn Wd+b65703javascrīpt:
K[H$ZIf}E&a65703document.referrer

16. 最小化、最大化、关闭窗口51Testing软件测试网'A2k ]u`u
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
\ N#u'W%Y7[ r?CX%F-|65703<param name="Command" value="Minimize"></object>
7h$s)o6K Pp/i N:q)X65703<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
$\[yj E,T!D65703<param name="Command" value="Maximize"></object>51Testing软件测试网 o8i*l m*d
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
P/p%`y5V8L(b65703<PARAM NAME="Command" VALUE="Close"></OBJECT>

<input type=button value=最小化 ōnclick=hh1.Click()>
_[,X7k6f F/\65703<input type=button value=最大化 ōnclick=hh2.Click()>51Testing软件测试网F2j hovm!T7h{j
<input type=button value=关闭 ōnclick=hh3.Click()>51Testing软件测试网"XW f4|5S:L#Pu
本例适用于IE

17.屏蔽功能键Shift,Alt,Ctrl51Testing软件测试网O$cC"@ ` O/e"e
<scrīpt>51Testing软件测试网w*n(OYV%A"^
function look(){51Testing软件测试网(bfi V3x*f
if(event.shiftKey)
gud l8W qM7U65703alert("禁止按Shift键!"); //可以换成ALT CTRL51Testing软件测试网H q$GL6C
}51Testing软件测试网:D2qb:H.~c6r
document.onkeydown=look;
Dz?c5cs(i65703</scrīpt>

18. 网页不会被缓存51Testing软件测试网Z+aAX9o[-j7M"W&R-F
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
i V;~ bbS'z#q65703<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
EF1|xGF65703<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">51Testing软件测试网'Rw?1R!L"}zJL c%E"b
或者<META HTTP-EQUIV="expires" CONTENT="0">

19.怎样让表单没有凹凸感?51Testing软件测试网 W3u*kuDV$I
<input type=text style="border:1 solid #000000">51Testing软件测试网!n/YST'e i,bt

6GzBXY65703<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom: 1 solid #000000"></textarea>

20.<div><span>&<layer>的区别?51Testing软件测试网P dB@,K8sL
<div>(division)用来定义大段的页面元素,会产生转行
@%jly-J5s!L65703<span>用来定义同一行内的元素,跟<div>的唯一区别是不产生转行51Testing软件测试网 o lXgp [^ z7E
<layer>是ns的标记,ie不支持,相当于<div>


,z6p-^8P1d$OW/^6570321.让弹出窗口总是在最上面:51Testing软件测试网bq lrht \,F9S
<body ōnblur="this.focus();">

22.不要滚动条?
Xe6j#l(p ?65703让竖条没有:51Testing软件测试网&w&p0^{Y&`Q4RW
<body style="overflow:scroll;overflow-y:hidden">51Testing软件测试网2d0S6[7]| x,k
</body>
7a/xh4d2{ u65703让横条没有:
J4zR3N+W(r;|65703<body style="overflow:scroll;overflow-x:hidden">51Testing软件测试网SR oK~$p
</body>51Testing软件测试网+Pt%iOA f-\
两个都去掉?更简单了51Testing软件测试网PR7Z4}.E1r @
<body scroll="no">51Testing软件测试网1gshslO
</body>

23.怎样去掉图片链接点击后,图片周围的虚线?
m%]Dv p!m+^65703<a href="#" ōnFocus="this.blur()"><img src="logo.jpg" border=0></a>

24.电子邮件处理提交表单51Testing软件测试网 ile9GuBkOSW
<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">51Testing软件测试网0~/r)q^&@*eq
<input type=submit>
Dn9g/yt.F8{:Obf r65703</form>

25.在打开的子窗口刷新父窗口的代码里如何写?51Testing软件测试网u)MO^{&`2Gx`
window.opener.location.reload()

26.如何设定打开页面的大小51Testing软件测试网E~#lR&E \9Jf
<body ōnload="top.resizeTo(300,200);">51Testing软件测试网7\(XT!NdL(}\0W
打开页面的位置<body ōnload="top.moveBy(300,200);">

27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动51Testing软件测试网EF}:?O8_
<STYLE>
{`UY;l"SS65703body51Testing软件测试网 \9a x*h1Q
{background-image:url(logo.gif); background-repeat:no-repeat;

background-position:center;background-attachment: fixed}51Testing软件测试网[i a-\As
</STYLE>

28. 检查一段字符串是否全由数字组成
X T9_:\0}65703<scrīpt language="Javascrīpt"><!--
s,v:I5f ^j3g65703function checkNum(str){return str.match(//D/)==null}51Testing软件测试网'\`!wx9e2U-XGoT7Vy
alert(checkNum("1232142141"))
.`h _/[fA65703alert(checkNum("123214214a1"))
?/n.b*c j8\N _7c65703// --></scrīpt>

29. 获得一个窗口的大小51Testing软件测试网1T7Zm5y1oW3OK
document.body.clientWidth; document.body.clientHeight

30. 怎么判断是否是字符51Testing软件测试网M,U4`['sv/qK/a
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");51Testing软件测试网!i^!P i?:K&|n
else alert("全是字符");

31.TEXTAREA自适应文字行数的多少51Testing软件测试网!e5tr u"A_p9j1b.K
<textarea rows=1 name=s1 cols=27 ōnpropertychange="this.style.posHeight=this.scrollHeight">
(?5U?t7W,e:S65703</textarea>

32. 日期减去天数等于第二个日期51Testing软件测试网;Uf*[MgT tlb W}
<scrīpt language=Javascrīpt>
4}7M/t~+ch(jA.qr65703function cc(dd,dadd)
.T!m"yFO{h65703{
7[9Dp~/R ?.i"L65703//可以加上错误处理51Testing软件测试网SC7FeB$~1s,\ u
var a = new Date(dd)
]3K8oB}+P O65703a = a.valueOf()51Testing软件测试网Hh"AFD$| av QV4e
a = a - dadd * 24 * 60 * 60 * 100051Testing软件测试网%~9Ew:L9?8A-k7S P
a = new Date(a)51Testing软件测试网C w{$L etUnP
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")51Testing软件测试网RJ(EsrUe
}
o5ZXT1IX,b-LO65703cc("12/23/2002",2)
S+s8_9l$If65703</scrīpt>

33. 选择了哪一个Radio
]'vt[Ez_65703<HTML><scrīpt language="vbscrīpt">51Testing软件测试网}F:_;{#`
function checkme()
]_P/Z\4g.C65703for each ob in radio1
B? HSvQ-F7L65703if ob.checked then window.alert ob.value
A0Joj Nh/~ ~65703next
a2I"Qi9g65703end function51Testing软件测试网6`~0Y_0SSyt
</scrīpt><BODY>51Testing软件测试网/Jqf j$Foy
<INPUT name="radio1" type="radio" value="style" checked>Style
+u Kv}7P d65703<INPUT name="radio1" type="radio" value="barcode">Barcode51Testing软件测试网 hnv)u2q?&k!j
<INPUT type="button" value="check" ōnclick="checkme()">51Testing软件测试网0G{.l"[eq|o
</BODY></HTML>

34.脚本永不出错
%V.Rb'l9|c [c#h7w0qc65703<scrīpt LANGUAGE="Javascrīpt">51Testing软件测试网G O'X2K C&`Ju;yI
<!-- Hide
?A s8{/zrN65703function killErrors() {
+\Zl XkW65703return true;
:m6_9g0c z%}&f65703}51Testing软件测试网2_X^\4?+V l
window.onerror = killErrors;51Testing软件测试网H6[5^Qp1lN
// -->
fD]xCOyo65703</scrīpt>

35.ENTER键可以让光标移到下一个输入框
m2J&kH_L65703<input ōnkeydown="if(event.keyCode==13)event.keyCode=9">

36. 检测某个网站的链接速度:
:SHu^_F/@65703把如下代码加入<body>区域中:51Testing软件测试网Pxm#t5h:CU8R
<scrīpt language=Javascrīpt>51Testing软件测试网F"y-X0_2_:J}i
tim=1
$y#p$B~VF65703setInterval("tim++",100)
;xt[4Z Ps(ke(?65703b=1

var autourl=new Array()
:^!vq!v.JV1OX65703autourl[1]="www.njcatv.net"51Testing软件测试网,L6Z:i,e0y
autourl[2]="javacool.3322.net"51Testing软件测试网+_QsRfV`
autourl[3]="www.sina.com.cn"51Testing软件测试网7v$A7L+HX9J3M
autourl[4]="www.nuaa.edu.cn"
ej fMxPn65703autourl[5]="www.cctv.com"

function butt(){
u.ho"X%Rmx2j.w(s65703document.write("<form name=autof>")51Testing软件测试网;H8qP;fn
for(var i=1;i<autourl.length;i++)
7QS(B*c d3vjK65703document.write("<input type=text name=txt"+i+" size=10 value=测试中……> =》<input type=text name=url"+i+" size=40> =》<input type=button value=GO51Testing软件测试网`#\gA |&}:~5M
onclick=window.open(this.form.url"+i+".value)><br>")
oh8GZ] s7t65703document.write("<input type=submit value=刷新></form>")
"M.U7z1fA_4`-`65703}51Testing软件测试网+jB `:aNhG?(G
butt()
2g!@i$ZT9[$O4t65703function auto(url){
+]$c3_Q4eZwb7f:`(_65703document.forms[0]["url"+b].value=url51Testing软件测试网C2r&M.Qkjn V
if(tim>200)51Testing软件测试网Kf nv4Y'[.fAk5l3d
{document.forms[0]["txt"+b].value="链接超时"}
o%u"bf8W8Y|65703else
wI L#R%EG3K6V65703{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"}51Testing软件测试网`xV%q8m%P
b++
o ^(Jbr"_:r;UP65703}
t1?J+^"Y A/p"f65703function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl+"/"+Math.random()+" width=1 height=1 ōnerror=auto("http://"+autourl+"")>")}
zO(vg1I8Y|h7Vs]65703run()</scrīpt>

37. 各种样式的光标
B5?,x4O @+cS ^4D65703auto :标准光标51Testing软件测试网/Mmh6E9v2sm#[5\
default :标准箭头
]$U2]Y*O"B65703hand :手形光标51Testing软件测试网S.\{#Qz$v`O1b#a
wait :等待光标
3rG0N+M AC7` M65703text :I形光标
-Xs5_8R _]!p)I65703vertical-text :水平I形光标51Testing软件测试网 x.dkq~y
no-drop :不可拖动光标
G+L7PF@f6j!b65703not-allowed :无效光标51Testing软件测试网cA3U(J2ejQW'E,nF6i
help :?帮助光标51Testing软件测试网g3G0P Gg
all-scroll :三角方向标
ES,P8k,PB65703move :移动标
mx!U-H"I\#_2X65703crosshair :十字标51Testing软件测试网?1?(u1E3O
e-resize
pNuEoY"ej65703n-resize51Testing软件测试网5kH#e B*T {l
nw-resize51Testing软件测试网y7S%As+[0B)Ti&r|
w-resize
{+Xs0`9dD65703s-resize51Testing软件测试网kiW/eADUl
se-resize51Testing软件测试网IS;d%kBMB.n R3J
sw-resize

38.页面进入和退出的特效51Testing软件测试网*me%M"T4c_/J
进入页面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
s}H H"J e-X9n.b b8F65703推出页面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)"> 
T*O$~C.zWBf65703这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23:51Testing软件测试网m6VRrK
  0 矩形缩小
(o.Rxy3a QpA65703  1 矩形扩大51Testing软件测试网Ca+BU*i j q5A
  2 圆形缩小51Testing软件测试网5G L4U(H!If [Ov
  3 圆形扩大51Testing软件测试网4D\$b#Xs
  4 下到上刷新
:Dr*Z v[/}]wX65703  5 上到下刷新
"sJX?D6|h(E x Yy65703  6 左到右刷新
FB:Qyu6|-Z65703  7 右到左刷新
%FJr9h`"v0l:k EXoZ65703  8 竖百叶窗51Testing软件测试网&[%?E,[\
  9 横百叶窗
#z7x-_4z$}7x([V65703  10 错位横百叶窗
%J dp*VHZ$Cp65703  11 错位竖百叶窗51Testing软件测试网'P)t%l7x%T&G
  12 点扩散
8mB~k]65703  13 左右到中间刷新51Testing软件测试网ns oR/}8aSV T
  14 中间到左右刷新51Testing软件测试网 D/p"UB n8] wD
  15 中间到上下
]8zf8DS"c65703  16 上下到中间51Testing软件测试网M)S;O_F-h$p G
  17 右下到左上51Testing软件测试网-bo1A/fr/zS9iY
  18 右上到左下51Testing软件测试网#ri ~o?T7od-~
  19 左上到右下51Testing软件测试网 ]sr n ^ @oV
  20 左下到右上51Testing软件测试网$J8]f:Y2bLD
  21 横条
8H9t;nI r*K65703  22 竖条51Testing软件测试网} A OH'|_9v
  23 以上22种随机选择一种

39.在规定时间内跳转
\3W"y"^ _65703<META http-equiv=V="REFRESH" content="5;URL=http://www.51js.com">

40.网页是否被检索
5z6t)G c2Y65703<meta name="ROBOTS" content="属性值">
3D/mo9H]W4b:[#X+n65703  其中属性值有以下一些:51Testing软件测试网9CU9i&v~*] Qg
  属性值为"all": 文件将被检索,且页上链接可被查询;51Testing软件测试网e G-| Z)d
  属性值为"none": 文件不被检索,而且不查询页上的链接;
qko k EG1YbP7S65703  属性值为"index": 文件将被检索;51Testing软件测试网EMVr$Xs(N~/q
  属性值为"follow": 查询页上的链接;51Testing软件测试网j){g9? D*w_
  属性值为"noindex": 文件不检索,但可被查询链接;51Testing软件测试网 ?i8m"D%W u'E*u^ td {
  属性值为"nofollow": 文件不被检索,但可查询页上的链接。


TAG:

 

评分:0

我来说两句

Open Toolbar