广西经贸职业技术学院论坛
标题:
[建站技术]实用:网页制作中常用的辅助代码
[打印本页]
作者:
月中水
时间:
2009-10-16 01:17
标题:
[建站技术]实用:网页制作中常用的辅助代码
点击返回上页代码:
$ v8 z1 T5 k" [$ D5 X$ B0 P
<form>
# i" m" B2 ~/ }# J" H, a* N
<p><input TYPE="button" VALUE="返回上一步"></p>
1 Z& m1 F7 Y \
</form>
. Y+ P$ @. Q- m2 W
8 Q; m% C3 N/ e7 U
弹出警告框代码:
! j' V$ T- A( ?' }! z
<form>
4 ~& m" v7 s. r& W/ Z
<p><input TYPE="button" VALUE="弹出警告框"></p>
! h- _: u+ C' Q/ V" v! X
</form>
) C9 \( {) r/ ^8 F
<script language="JavaScript"><!--
$ M; s0 a5 h4 ]% P! z
function AlertButton(){window.alert("要多多光临呀!");}
, t. T( {9 H+ d& ~
// --></script>
: k% `! g" a4 n
( k; G9 }* V7 F& k6 U R
点击打开新窗口
7 U( A$ e/ X: E; D* z# w$ @, {) y! h* j
<form>
% M8 |+ N; V+ f6 Q4 B
<p><input TYPE="button" VALUE="打开新窗口"></p>
. k# N: \$ s; j9 ?* u, o
</form>
+ U& r( W5 @: H6 _5 n: e% |
<script language="JavaScript"><!--
" s1 y0 ^( F8 f9 [, q P: L5 g- [) N& h
function NewWindow(){window.open("http://www.mcmx.com","","height=240,width=340,status=no,location=no,
0 U- q! a, h2 }, x3 y
toolbar=no,directories=no,menubar=no");}
$ N% l6 x$ u- ~8 @' V
// --></script></body>
8 l4 D3 v- ~) p) U! r7 J8 O( p4 S
, ~7 a( V6 g X i- X1 Y$ ]3 i/ s
删除记录时弹出确认框:
" l# { J( d: K7 e1 N
<script LANGUAGE="VBSCRIPT">
' I$ i' m( j, l- I# W0 Y! ?# ^
a=msgbox("真的要删除该记录吗?",1,"注意")
0 O5 s% e; v: C- o
if a=1 then
9 s1 ^/ c* Y: ~% i$ V
location="Dodelete.asp?id=" //指向执行删除的页面Dodelete.asp
/ `& n- s" @! m# L5 f+ [0 Y" n
else
S3 \- L- Y- H* }) n
history.go(-1)
# j1 x- G# G) B l1 b
end if
* i9 T% M( j" l0 ]+ l; n
</script>
h( j0 ]4 I" e2 a
$ k/ G/ E! u; d* B! s t! {
关闭打开的窗口
; M2 l# c0 k! N
< a href="/">关闭窗口</a>
1 f, m+ j# z! {$ @/ }
: } j& }1 i+ U7 v! o; o. {3 N
清空INPUT且选定
. |; ` }! r5 U' [8 {* Q0 t
onClick="Javascript:this.value=''"
3 B* p( p/ I* j3 Q0 q1 s5 X6 _
) B1 }7 t. x7 q
右键屏蔽
0 O2 C- A0 P" F" z8 s
<body oncontextmenu=self.event.returnValue=false>
3 Z$ D8 d( [' }9 t1 J6 {
! [) f& ^2 m" } m) K& N
连串英文自动换行的解决方法 IE5.5
$ [% T% y6 ~- Q* r* C5 S
style="LEFT: 0px; WIDTH: 100%; WORD-WRAP: break-word" 你可修改为指定的大小如 200px
# M. s1 }9 l, @( l( Y; E2 x1 U
3 ^4 }6 m; s8 v. U+ d6 E. e* e
图片“重置”按钮
7 ?: r# r% v5 Z+ y) v6 c# Z4 D
<script language="jscript">
" ]) H5 F2 o4 W& I& i- X
function myreset()
K( F9 r$ R; o
{ document.login.reset();
, f" S+ ]1 d+ E# G1 t
document.login.focus();}
5 Y4 D4 ?( [/ A! ~5 n/ v
</script>
* ~8 ` `8 q* X6 K+ z& `7 f1 M- p
<img src="image/reclear.gif" width="69" height="20" style="cursor:hand"
3 V1 V$ Z4 m0 P! v* p+ H7 @9 p1 D9 t& o
8 l5 _1 l) a) P1 ~
画细线表格
5 h- x8 ]4 X' F: N5 u y
<table style="border-collapse: collapse">
4 s) {1 F, u7 ]9 W) h! h( X
' G8 P6 y5 S) I3 R) u! u
状态栏信息
" W+ Z9 {( }, q: e' A9 x
<form>
5 E- r. ?7 l8 R$ W6 L% R5 i, p
<p><input TYPE="button" VALUE="状态栏信息"></p>
% ?: r) E* K8 z3 z% Y
</form>
& v! L4 F1 `7 s' P1 \
<script language="JavaScript"><!--
6 Q7 ^- n8 v; n8 o
function StatusButton(){window.status="要多多光临呀!";}
/ f* V* J' w* R% h8 N
// --></script>
. b4 R* m8 }5 x) f. e! w) ]
* ]. [5 v7 C+ C- l0 u y+ G4 o$ \
最小化、最大化、关闭窗口
, W! |/ }2 T+ _/ B
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
3 F+ x' P3 g& c6 T/ r
<param name="Command" value="Minimize"></object>
8 Z; f6 Y w! X8 M( ?* D* i; @
<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
# {+ F3 s4 o+ B/ j
<param name="Command" value="Maximize"></object>
% p% o% w ?1 o( m. M( Y7 u
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
+ g, O0 k8 r) N7 X0 z/ ]& V$ ]
<PARAM NAME="Command" VALUE="Close"></OBJECT>
% Q6 ]/ n; R/ J4 c) R! O
" D4 C# r+ Z/ o
<input type=button value=最小化 onclick=hh1.Click()>
: U7 Q" d/ _5 h, X
<input type=button value=最大化 onclick=hh2.Click()>
! K: c% S. r! F8 S& i. \
<input type=button value=关闭 onclick=hh3.Click()>
& e9 c9 o- i* |; p* j7 @
本例适用于IE
* I" z8 J0 n" C; f4 T; G
% `. [$ ?; C2 k# x! W8 e2 }3 i9 _
隐藏状态栏里出现的LINK信息
" t4 d* Y; c' J) p
<a href="http://";>梦想天空</a>
; w$ l/ p" G4 k+ Y! I
7 E4 ? {- i# A* E+ x
文本框自动滚动条
( L% F+ [/ |4 q; z- m, t
<textarea name=words rows=18 cols=26 style="border:1 solid #000000;background-color:white; font-size:9pt; width:188; overflow:auto" wrap=hard></textarea>
/ D1 k0 i: c5 `
1 L4 `8 N0 i2 M* L* h2 C' r
全选并复制
* [6 q6 V% U2 B$ E/ [6 J. ?0 X9 P
<FORM name=test><INPUT type=button value=全选并复制><BR><TEXTAREA name=select1 rows=3 cols=46>你好,欢迎您的光临!</TEXTAREA>
6 z8 L. X) t- L* w9 d" w; ]1 t
</FORM>
) z# {# p) A/ ]8 T
<SCRIPT language=Javascript>
* r9 f' U7 v8 \" Z3 c( g: [
<!--
! R3 a, i1 A7 J. m/ s5 r4 Z
, G2 {4 o7 I: v. Y6 z+ `" o+ Q
var copytoclip=1
% A( C% Q) H. ?& Q
) l$ h0 e$ s. s+ }# j6 M3 k
function HighlightAll(theField) {
1 }1 f( s( `7 }
var tempval=eval("document."+theField)
% @2 }9 H3 s8 P
tempval.focus()
, \, j1 P5 t& _- a
tempval.select()
3 G( ?8 L$ n. ] ]& f6 U( ^- I
if (document.all&©toclip==1){
* k: H; Y/ E' h/ l- |; p' T
therange=tempval.createTextRange()
( x3 D) Q4 r* f' b1 [' _/ L
therange.execCommand("Copy")
0 t$ Q: F# T. E+ K. _
window.status="Contents highlighted and copied to clipboard!"
R6 ^2 i1 \. i( K* n
setTimeout("window.status=''",1800)
6 L1 o' a8 W- G. t/ g7 E
}
$ J- ~3 Y: [( E: B6 C! o2 q, L: ]# d
}
0 X4 }1 p1 Z( {$ e1 u, E `; O
//-->
! k: S' h1 P+ }4 l2 z5 M
</SCRIPT>
" n/ ?8 k) Z3 O8 Y1 Z: L0 x
; d& _2 M6 |" S% ]0 Z
屏蔽JAVASCRIPT错误
l0 t4 g! l( k$ v$ r# m0 [2 i" @
<script language="JavaScript">
& A, B+ \$ a8 p8 s& \
<!--
! j$ V' v- O* k c& D& B) c
function killErrors(){
! n# O( q# U; h% j" J s
return true;
+ ?# p' w D' Y, t" R2 w" N
}
" ^9 R% n$ x6 ~+ }' p
window.onerror = killErrors;
5 Z% n6 R1 @' ?: U1 Y; b
-->
7 Z$ {; C) k6 L
</script>
" x" @1 x2 @: z1 X# P( l" i
# k2 C7 d/ ]1 Y
关闭子窗口时刷新父窗口
7 c$ m r8 m' b! F; G# A$ y
<script language="JavaScript">
- v: g! L" r( _% F' \
<!--
4 d$ u( s. M, e% q: H- U
self.opener.location.reload();
- Q7 n& K% |' K* y3 M5 e4 n
window.close()
0 F9 c' n7 P D* T3 f
-->
o5 @5 u& t2 x+ F
</script>
1 p' r( t, K$ W
" ?8 q' X, y: Z
+ D. W+ K9 E+ r% i
背景色变换
, B. u, g! Y1 [( B; e/ f- n& }, P4 {8 |
<form>
' l5 O5 w1 e( ~% I
<p><input TYPE="button" VALUE="背景色变换"></p>
) |7 I) @" e' \( V+ h3 H: T5 J
</form>
) B' p% |* Q% C& ^4 I( A
<script>function BgButton(){
" k9 [7 B# a' D& H h# P
if (document.bgColor=='#00ffff')
3 i+ _2 g, \0 u3 q
{document.bgColor='#ffffff';}
?+ n6 }6 y- F9 g. M0 O; l
else{document.bgColor='#00ffff';}
9 \1 j) C X( k! z: v
}
. g. E( M) g* u, ?
</script>
; @1 a5 X) ^$ \& ] g
' ^3 u% E/ k3 z7 X2 k, @
检查一段字符串是否全由数字组成
4 ^7 s3 c2 d( Q
<script language="Javascript"><!--
$ ~; b. {) U5 K% S E! s" |6 N# {
function checkNum(str){return str.match(//D/)==null}
/ @- q- @( r+ T' f7 {$ j
alert(checkNum("1232142141"))
8 N0 r. n' C3 P7 _! T. V9 r; {
alert(checkNum("123214214a1"))
0 V1 J( I) \) }; C: F6 ^, f
// --></script>
& O% \, m `2 l) v# z# x
! z& F d$ e. K
判断是否是字符
% B( f; i8 L7 @5 J
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");
* P: w- K4 I* ^2 q8 Z, S
& `7 v Q2 @2 G
点击刷新代码:
" B) N" n6 d9 _
<form>
* w$ o5 Y( O; d0 ~( \ M# j
<p><input TYPE="button" VALUE="刷新按钮一"></p>
3 e% f- v- A d4 @9 U4 R) w8 o
</form>
. n9 w7 X0 Z' J4 j$ e, U# Q* a4 O, j
<script language="JavaScript"><!--
. A }* V7 u: x
function ReloadButton(){location.href="allbutton.htm";}
2 h/ w ?% \) f4 \% E
// --></script>
4 p, J( m8 l3 ^, ^
+ j( ?4 ~- h' o% c0 p: O, o
让层不被控件复盖代码:
! a( R( e; _: z" \( ^3 F
<div z-Index:2><object xxx></object></div> # 前面
' K" L/ }* c: K, F
<div z-Index:1><object xxx></object></div> # 后面
: I+ L+ g6 c! x1 s6 A
<div id="Layer2" style="position:absolute; top:40;width:400px; height:95px;z-index:2"><table height=100% width=100% bgcolor="#ff0000"><tr><td height=100% width=100%></td></tr></table><iframe width=0 height=0></iframe></div>
% y) E _$ G, {, X6 ]
<div id="Layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>
# i9 b; f% s4 ~' X
! u6 c3 F) T" B; Q' M L
让层的相对定位
8 T. n A/ B. S
<div id="Layer1" style="position:relative; left:0px; top:0px; width:0px; height:0px;z-index:1">
. W' e" [; y$ o/ z
<div id="Layer2" style="position:absolute; left:500px; top:0px; width:220px; height:220px; z-index:1">
% W/ F8 l6 S- W
内容
8 r! r( e) M( I$ {; z M0 E$ R( `
</div></div>
8 [/ B" r0 _& g
4 \7 K* ^) u" ?- q3 n
Flash代码以及背景透明
) c$ [; F( X& b- Y; l3 v- Y
<object classid="clsid
27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="200" height="200">
9 Y2 o1 J/ o" r
<param name="movie" value="文件">
% ^8 t z. \! [# g% O# }0 Z
<param name="quality" value="high">
' c; M& ?8 D% z' Q! v
<param name="wmode" value="transparent">
q0 @* K/ @. i* h/ A7 y
<embed src="images/fish.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="220" height="220"></embed></object>
欢迎光临 广西经贸职业技术学院论坛 (http://gxjmbbs.com/)
Powered by Discuz! X3.2