55种网页常用小技巧(javascript)

None.gif 1. οncοntextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键 
None.gif
< table  border oncontextmenu =return(false) >< td > no table >  可用于Table 
None.gif2. 
< body  onselectstart ="return false" >  取消选取、防止复制 
None.gif3. οnpaste="return false" 不准粘贴 
None.gif4. οncοpy="return false;" oncut="return false;" 防止复制 
None.gif5. 
< link  rel ="Shortcut Icon"  href ="favicon.ico" >  IE地址栏前换成自己的图标 
None.gif6. 
< link  rel ="Bookmark"  href ="favicon.ico" >  可以在收藏夹中显示出你的图标 
None.gif7. 
< input  style ="ime-mode:disabled" >  关闭输入法 
None.gif8. 永远都会带着框架 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif  
InBlock.gif
9. 防止被人frame 
InBlock.gif
<SCRIPT LANGUAGE=javascript> 
InBlock.gif
10. 网页将不能被另存为 
InBlock.gif
<noscript><iframe src=*.html>iframe>noscript> 
InBlock.gif
11<input type=button value=查看网页源代码 
InBlock.gifonclick
="window.location = "view-source:""http://www.pconline.com.cn""> 
InBlock.gif
12.删除时确认 
InBlock.gif
<a href="javascript:if(confirm("确实要删除吗?"))location="boos.asp?&areyou=删除&page=1"">删除a> 
InBlock.gif
13. 取得控件的绝对位置 
InBlock.gif
//javascript 
InBlock.gif
<script language="javascript"> 
ExpandedSubBlockStart.gifContractedSubBlock.gif
function getIE(e)dot.gif
InBlock.gif
var t=e.offsetTop; 
InBlock.gif
var l=e.offsetLeft; 
ExpandedSubBlockStart.gifContractedSubBlock.gif
while(e=e.offsetParent)dot.gif
InBlock.gift
+=e.offsetTop; 
InBlock.gifl
+=e.offsetLeft; 
ExpandedSubBlockEnd.gif}
 
InBlock.gifalert(
"top="+t+"/nleft="+l); 
ExpandedBlockEnd.gif}
 
None.gif
script >  
None.gif//VBScript 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="VBScript" > dot.gif <!-- 
InBlock.gif
function getIE() 
InBlock.gif
dim t,l,a,b 
InBlock.gif
set a=document.all.img1 
InBlock.gift
=document.all.img1.offsetTop 
InBlock.gifl
=document.all.img1.offsetLeft 
InBlock.gif
while a.tagName<>"BODY" 
InBlock.gif
set a = a.offsetParent 
InBlock.gift
=t+a.offsetTop 
InBlock.gifl
=l+a.offsetLeft 
InBlock.gif
wend 
InBlock.gif
msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置" 
InBlock.gif
end function 
ExpandedBlockEnd.gif
-->
script >  
None.gif14. 光标是停在文本框文字的最后 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif  
InBlock.gif
function cc() 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
var e = event.srcElement; 
InBlock.gif
var r =e.createTextRange(); 
InBlock.gifr.moveStart(
"character",e.value.length); 
InBlock.gifr.collapse(
true); 
InBlock.gifr.select(); 
ExpandedBlockEnd.gif}
 
None.gif
script >  
None.gif
< input  type =text  name =text1  value ="123"  onfocus ="cc()" >  
None.gif15. 判断上一页的来源 
None.gifjavascript: 
None.gifdocument.referrer 
None.gif16. 最小化、最大化、关闭窗口 
None.gif
< object  id =hh1  classid ="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11" >  
None.gif
< param  name ="Command"  value ="Minimize" > object >  
None.gif
< object  id =hh2  classid ="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11" >  
None.gif
< param  name ="Command"  value ="Maximize" > object >  
None.gif
< OBJECT  id =hh3  classid ="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" >  
None.gif
< PARAM  NAME ="Command"  VALUE ="Close" > OBJECT >  
None.gif
< input  type =button  value =最小化  onclick =hh1.Click() >  
None.gif
< input  type =button  value =最大化  onclick =hh2.Click() >  
None.gif
< input  type =button  value =关闭  onclick =hh3.Click() >  
None.gif本例适用于IE 
None.gif17.屏蔽功能键Shift,Alt,Ctrl 
ExpandedBlockStart.gifContractedBlock.gif
< script > dot.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif
function look()dot.gif
InBlock.gif
if(event.shiftKey) 
InBlock.gifalert(
"禁止按Shift键!"); //可以换成ALT CTRL 
ExpandedSubBlockEnd.gif
}
 
ExpandedBlockEnd.gifdocument.onkeydown
=look; 
None.gif
script >  
None.gif18. 网页不会被缓存 
None.gif
< META  HTTP-EQUIV ="pragma"  CONTENT ="no-cache" >  
None.gif
< META  HTTP-EQUIV ="Cache-Control"  CONTENT ="no-cache, must-revalidate" >  
None.gif
< META  HTTP-EQUIV ="expires"  CONTENT ="Wed, 26 Feb 1997 08:21:57 GMT" >  
None.gif或者
< META  HTTP-EQUIV ="expires"  CONTENT ="0" >  
None.gif19.怎样让表单没有凹凸感? 
None.gif
< input  type =text  style ="border:1 solid #000000" >  
None.gif或 
None.gif
< input  type =text  style ="border-left:none; border-right:none; border-top:none; border-bottom: 
None.gif1 solid #000000"
> textarea >  
None.gif20.
< div >< span > & < layer > 的区别? 
None.gif
< div > (division)用来定义大段的页面元素,会产生转行 
None.gif
< span > 用来定义同一行内的元素,跟 < div > 的唯一区别是不产生转行 
None.gif
< layer > 是ns的标记,ie不支持,相当于 < div >  
None.gif21.让弹出窗口总是在最上面: 
None.gif
< body  onblur ="this.focus();" >  
None.gif22.不要滚动条? 
None.gif让竖条没有: 
None.gif
< body  style ="overflow:scroll;overflow-y:hidden" >  
None.gif
body >  
None.gif让横条没有: 
None.gif
< body  style ="overflow:scroll;overflow-x:hidden" >  
None.gif
body >  
None.gif两个都去掉?更简单了 
None.gif
< body  scroll ="no" >  
None.gif
body >  
None.gif23.怎样去掉图片链接点击后,图片周围的虚线? 
None.gif
< href ="#"  onFocus ="this.blur()" >< img  src ="logo.jpg"  border =0 > a >  
None.gif24.电子邮件处理提交表单 
None.gif
< form  name ="form1"  method ="post"  action ="mailto:****@***.com"  enctype ="text/plain" >  
None.gif
< input  type =submit >  
None.gif
form >  
None.gif25.在打开的子窗口刷新父窗口的代码里如何写? 
None.gifwindow.opener.location.reload() 
None.gif26.如何设定打开页面的大小 
None.gif
< body  onload ="top.resizeTo(300,200);" >  
None.gif打开页面的位置
< body  onload ="top.moveBy(300,200);" >  
None.gif27.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动 
ExpandedBlockStart.gifContractedBlock.gif
< STYLE > dot.gif  
InBlock.gifbody 
ExpandedSubBlockStart.gifContractedSubBlock.gif
{dot.gif}{background-image:url(logo.gif); background-repeat:no-repeat; 
ExpandedBlockEnd.gifbackground-position
:center;background-attachment: fixed}
 
None.gif
STYLE >  
None.gif28. 检查一段字符串是否全由数字组成 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif  
InBlock.gif
29. 获得一个窗口的大小 
InBlock.gifdocument.body.clientWidth; document.body.clientHeight 
InBlock.gif
30. 怎么判断是否是字符 
InBlock.gif
if (/[^/x00-/xff]/g.test(s)) alert("含有汉字"); 
InBlock.gif
else alert("全是字符"); 
InBlock.gif
31.TEXTAREA自适应文字行数的多少 
InBlock.gif
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight"> 
InBlock.gif
textarea> 
InBlock.gif
32. 日期减去天数等于第二个日期 
InBlock.gif
<script language=javascript> 
InBlock.gif
function cc(dd,dadd) 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
//可以加上错误处理 
InBlock.gif
var a = new Date(dd) 
InBlock.gif
= a.valueOf() 
InBlock.gif
= a - dadd * 24 * 60 * 60 * 1000 
InBlock.gif
= new Date(a) 
InBlock.gifalert(a.getFullYear() 
+ "" + (a.getMonth() + 1+ "" + a.getDate() + ""
ExpandedSubBlockEnd.gif}
 
ExpandedBlockEnd.gifcc(
"12/23/2002",2

None.gif script >  
None.gif33. 选择了哪一个Radio 
ExpandedBlockStart.gifContractedBlock.gif
< HTML >< script  language ="vbscript" > dot.gif  
InBlock.gif
function checkme() 
InBlock.gif
for each ob in radio1 
InBlock.gif
if ob.checked then 
InBlock.gifwindow.alert ob.value 
InBlock.gif
next 
ExpandedBlockEnd.gif
end function 
None.gif
script >< BODY >  
None.gif
< INPUT  name ="radio1"  type ="radio"  value ="style"  checked > Style 
None.gif
< INPUT  name ="radio1"  type ="radio"  value ="barcode" > Barcode 
None.gif
< INPUT  type ="button"  value ="check"  onclick ="checkme()" >  
None.gif
BODY > HTML >  
None.gif34.脚本永不出错 
ExpandedBlockStart.gifContractedBlock.gif
< SCRIPT  LANGUAGE ="javascript" > dot.gif  
InBlock.gif
 
None.gif
SCRIPT >  
None.gif35.ENTER键可以让光标移到下一个输入框 
None.gif
< input  onkeydown ="if(event.keyCode==13)event.keyCode=9" >  
None.gif36. 检测某个网站的链接速度: 
None.gif把如下代码加入
< body > 区域中: 
ExpandedBlockStart.gifContractedBlock.gif
< script  language =javascript > dot.gif  
InBlock.giftim
=1 
InBlock.gifsetInterval(
"tim++",100
InBlock.gifb
=1 
InBlock.gif
var autourl=new Array() 
InBlock.gifautourl[
1]="www.njcatv.net" 
InBlock.gifautourl[
2]="javacool.3322.net" 
InBlock.gifautourl[
3]="www.sina.com.cn" 
InBlock.gifautourl[
4]="www.nuaa.edu.cn" 
InBlock.gifautourl[
5]="www.cctv.com" 
ExpandedSubBlockStart.gifContractedSubBlock.gif
function butt()dot.gif
InBlock.gifdocument.write(
""
InBlock.gif
for(var i=1;i<autourl.length;i++
InBlock.gifdocument.write(
""+i+" size=10 value=测试中……> =》InBlock.gifname=url"+i+" size=40> =》InBlock.gifοnclick=window.open(this.form.url"+i+".value)>
"
InBlock.gifdocument.write(
""
ExpandedSubBlockEnd.gif}
 
InBlock.gifbutt() 
ExpandedSubBlockStart.gifContractedSubBlock.gif
function auto(url)dot.gif
InBlock.gifdocument.forms[
0]["url"+b].value=url 
InBlock.gif
if(tim>200
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{document.forms[0]["txt"+b].value="链接超时"} 
InBlock.gif
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{document.forms[0]["txt"+b].value="时间"+tim/10+""} 
InBlock.gifb
++ 
ExpandedSubBlockEnd.gif}
 
ExpandedSubBlockStart.gifContractedSubBlock.gif
function run()dot.gif{for(var i=1;i<autourl.length;i++)document.write(""+autourl+"/"+Math.random()+" width=1 height=1 
InBlock.gifοnerrοr=auto(
"http://"+autourl+"")>")} 
ExpandedBlockEnd.gif
run()
script >  
None.gif37. 各种样式的光标 
None.gifauto :标准光标 
None.gifdefault :标准箭头 
None.gifhand :手形光标 
None.gifwait :等待光标 
None.giftext :I形光标 
None.gifvertical-text :水平I形光标 
None.gifno-drop :不可拖动光标 
None.gifnot-allowed :无效光标 
None.gifhelp :?帮助光标 
None.gifall-scroll :三角方向标 
None.gifmove :移动标 
None.gifcrosshair :十字标 
None.gife-resize 
None.gifn-resize 
None.gifnw-resize 
None.gifw-resize 
None.gifs-resize 
None.gifse-resize 
None.gifsw-resize 
None.gif38.页面进入和退出的特效 
None.gif进入页面
< meta  http-equiv ="Page-Enter"  content ="revealTrans(duration=x, transition=y)" >  
None.gif推出页面
< meta  http-equiv ="Page-Exit"  content ="revealTrans(duration=x, transition=y)" >    
None.gif这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使用哪种特效,取值为1-23: 
None.gif  0 矩形缩小 
None.gif  1 矩形扩大 
None.gif  2 圆形缩小 
None.gif  3 圆形扩大 
None.gif  4 下到上刷新 
None.gif  5 上到下刷新 
None.gif  6 左到右刷新 
None.gif  7 右到左刷新 
None.gif  8 竖百叶窗 
None.gif  9 横百叶窗 
None.gif  10 错位横百叶窗 
None.gif  11 错位竖百叶窗 
None.gif  12 点扩散 
None.gif  13 左右到中间刷新 
None.gif  14 中间到左右刷新 
None.gif  15 中间到上下 
None.gif  16 上下到中间 
None.gif  17 右下到左上 
None.gif  18 右上到左下 
None.gif  19 左上到右下 
None.gif  20 左下到右上 
None.gif  21 横条 
None.gif  22 竖条 
None.gif  23 以上22种随机选择一种 
None.gif39.在规定时间内跳转 
None.gif
< META  http-equiv =V="REFRESH"  content ="5;URL=http://www.51js.com" >  
None.gif40.网页是否被检索 
None.gif
< meta  name ="ROBOTS"  content ="属性值" >  
None.gif  其中属性值有以下一些: 
None.gif  属性值为"all": 文件将被检索,且页上链接可被查询; 
None.gif  属性值为"none": 文件不被检索,而且不查询页上的链接; 
None.gif  属性值为"index": 文件将被检索; 
None.gif  属性值为"follow": 查询页上的链接; 
None.gif  属性值为"noindex": 文件不检索,但可被查询链接; 
None.gif  属性值为"nofollow": 文件不被检索,但可查询页上的链接。 
None.gif41、email地址的分割 
None.gif把如下代码加入
< body > 区域中 
None.gif
< href ="mailto:[email protected]" > [email protected] a >  
None.gif42、流动边框效果的表格 
None.gif把如下代码加入
< body > 区域中 
ExpandedBlockStart.gifContractedBlock.gif
< SCRIPT > dot.gif  
InBlock.gifl
=Array(6,7,8,9,'a','b','b','c','d','e','f') 
InBlock.gifNx
=5;Ny=35 
InBlock.gift
=""+((Nx+2)*16)+">" 
InBlock.gif
for(x=Nx;x<Nx+Ny;x++
InBlock.gift
+=""+x+"> " 
InBlock.gift
+=""+(Nx-1)+"> "+(Ny-2)+" rowspan="+(Nx)+"> "+(Nx+Ny)+">" 
InBlock.gif
for(x=2;x<=Nx;x++
InBlock.gift
+=""+(Nx-x)+"> "+(Ny+Nx+x-1)+"> " 
InBlock.gift
+="" 
InBlock.gif
for(x=Ny;x>0;x--
InBlock.gift
+=""+(x+Nx*2+Ny-1)+"> " 
InBlock.gifdocument.write(t
+""
InBlock.gif
var N=Nx*2+Ny*2 
ExpandedSubBlockStart.gifContractedSubBlock.gif
function f1(y)dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
for(i=0;i<N;i++)dot.gif
InBlock.gifc
=(i+y)%20;if(c>10)c=20-
ExpandedSubBlockEnd.gifdocument.all[
"a_mo"+(i)].bgColor="'#0000"+l[c]+l[c]+"'"}
 
InBlock.gify
++ 
ExpandedSubBlockEnd.gifsetTimeout('f1('
+y+')','1')}
 
ExpandedBlockEnd.giff1(
1
None.gif
SCRIPT >  
None.gif43、javascript主页弹出窗口技巧 
None.gif窗口中间弹出 
ExpandedBlockStart.gifContractedBlock.gif
< script > dot.gif  
ExpandedBlockEnd.gifwindow.open(
"http://www.cctv.com","","width=400,height=240,top="+(screen.availHeight-240)/2+",left="+(screen.availWidth-400)/2); 
None.gif
script >  
None.gif============ 
None.gif
< html >  
None.gif
< head >  
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="LiveScript" > dot.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif
function WinOpen() dot.gif
InBlock.gifmsg
=open("","DisplayWindow","toolbar=no,directories=no,menubar=no"); 
InBlock.gifmsg.document.write(
"哈 罗!"); 
InBlock.gifmsg.document.write(
"

酷 毙 了!

这 是javascript所 开 的 视 窗!

"); 
ExpandedBlockEnd.gif}
 
None.gif
script >  
None.gif
head >  
None.gif
< body >  
None.gif
< form >  
None.gif
< input  type ="button"  name ="Button1"  value ="Push me"  onclick ="WinOpen()" >  
None.gif
form >  
None.gif
body >  
None.gif
html >  
None.gif============== 
None.gif一、在下面的代码中,你只要单击打开一个窗口,即可链接到赛迪网。而当你想关闭时,只要单击一下即可关闭刚才打开的窗口。 
None.gif  代码如下: 
ExpandedBlockStart.gifContractedBlock.gif  
< SCRIPT  language ="javascript" > dot.gif  
InBlock.gif  
<-- 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
function openclk() dot.gif
InBlock.gif  another
=open('http://www.ccidnet.com','NewWindow'); 
ExpandedSubBlockEnd.gif
  }
 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
function closeclk() dot.gif
InBlock.gif  another.close(); 
ExpandedSubBlockEnd.gif  }
 
InBlock.gif  
//--> 
ExpandedBlockEnd.gif
  
SCRIPT >  
None.gif  
< FORM >  
None.gif  
< INPUT  TYPE ="BUTTON"  NAME ="open"  value ="打开一个窗口"  onClick ="openclk()" >  
None.gif  
< BR >  
None.gif  
< INPUT  TYPE ="BUTTON"  NAME ="close"  value ="关闭这个窗口"  onClick ="closeclk()" >  
None.gif  
FORM >  
None.gif  二、上面的代码也太静了,为何不来点动感呢?如果能给页面来个降落效果那该多好啊! 
None.gif  代码如下: 
ExpandedBlockStart.gifContractedBlock.gif  
< script > dot.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif  
function drop(n) dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif  
if(self.moveBy)dot.gif
InBlock.gif  self.moveBy (
0-900); 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
for(i = n; i > 0; i--)dot.gif
InBlock.gif  self.moveBy(
03); 
ExpandedSubBlockEnd.gif  }
 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
for(j = 8; j > 0; j--)dot.gif
InBlock.gif  self.moveBy(
0,j); 
InBlock.gif  self.moveBy(j,
0); 
InBlock.gif  self.moveBy(
0-j); 
InBlock.gif  self.moveBy(
-j,0); 
ExpandedSubBlockEnd.gif  }
 
ExpandedSubBlockEnd.gif  }
 
ExpandedSubBlockEnd.gif  }
 
ExpandedBlockEnd.gif  
script >  
None.gif  
< body  onLoad ="drop(300)" >  
None.gif  三、讨厌很多网站总是按照默认窗口打开,如果你能随心所欲控制打开的窗口那该多好。 
None.gif  代码如下: 
ExpandedBlockStart.gifContractedBlock.gif  
< SCRIPT  LANGUAGE ="javascript" > dot.gif  
InBlock.gif  
<-- Begin 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
function popupPage(l, t, w, h) dot.gif
InBlock.gif  
var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=yes" + 
InBlock.gif  
",left=" + l + ",top=" + t + ",width=" + w + ",height=" + h; 
InBlock.gif  
var URL = "http://www.80cn.com"
InBlock.gif  popup 
= window.open(URL,"MenuPopup",windowprops); 
ExpandedSubBlockEnd.gif  }
 
InBlock.gif  
// End --> 
ExpandedBlockEnd.gif
  
script >  
None.gif  
< table >  
None.gif  
< tr >  
None.gif  
< td >  
None.gif  
< form  name =popupform >  
None.gif  
< pre >  
None.gif  打开页面的参数
< br >  
None.gif  离开左边的距离: 
< input  type =text  name =left  size =2  maxlength =4 >  pixels 
None.gif  离开右边的距离: 
< input  type =text  name =top  size =2  maxlength =4 >  pixels 
None.gif  窗口的宽度: 
< input  type =text  name =width  size =2  maxlength =4 >  pixels 
None.gif  窗口的高度: 
< input  type =text  name =height  size =2  maxlength =4 >  pixels 
None.gif  
pre >  
None.gif  
< center >  
None.gif
None.gif
< input  type =button  value ="打开这个窗口!"  onClick ="popupPage(this.form.left.value, this.form.top.value, this.form.width.value, this.form.height.value)" >  
None.gif  
center >  
None.gif  
form >  
None.gif  
td >  
None.gif  
tr >  
None.gif  
table > 你只要在相对应的对话框中输入一个数值即可,将要打开的页面的窗口控制得很好。 
None.gif44、页面的打开移动 
None.gif把如下代码加入
< body > 区域中 
ExpandedBlockStart.gifContractedBlock.gif
< SCRIPT  LANGUAGE ="javascript" > dot.gif  
InBlock.gif
 
ExpandedBlockEnd.gif//
 End --> 
None.gif
script >  
None.gif45、显示个人客户端机器的日期和时间 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="LiveScript" > dot.gif  
InBlock.gif
 
None.gif
script >  
None.gif46、自动的为你每次产生最後修改的日期了: 
None.gif
< html >  
None.gif
< body >  
None.gifThis is a simple HTML- page. 
None.gif
< br >  
None.gifLast changes: 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="LiveScript" > dot.gif  
InBlock.gif
 
None.gif
script >  
None.gif
body >  
None.gif
html >  
None.gif47、不能为空和邮件地址的约束: 
None.gif
< html >  
None.gif
< head >  
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif  
InBlock.gif
 
None.gif
script >  
None.gif
head >  
None.gif
< body >  
None.gif
< form  name ="first" >  
None.gifEnter your name:
< br >  
None.gif
< input  type ="text"  name ="text1" >  
None.gif
< input  type ="button"  name ="button1"  value ="输 入 测 试"  onClick ="test1(this.form)" >  
None.gif
< P >  
None.gifEnter your e-mail address:
< br >  
None.gif
< input  type ="text"  name ="text2" >  
None.gif
< input  type ="button"  name ="button2"  value ="输 入 测 试"  onClick ="test2(this.form)" >  
None.gif
body >  
None.gif48、跑马灯 
None.gif
< html >  
None.gif
< head >  
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript" > dot.gif  
InBlock.gif
 
None.gif
script >  
None.gif
head >  
None.gif
< body  onLoad ="scroll();return true;" >  
None.gif这里可显示您的网页 ! 
None.gif
body >  
None.gif
html >  
None.gif49、在网页中用按钮来控制前页,后页和主页的显示。 
None.gif
< html >  
None.gif
< body >  
None.gif
< FORM  NAME ="buttonbar" >  
None.gif
< INPUT  TYPE ="button"  VALUE ="Back"  onClick ="history.back()" >  
None.gif
< INPUT  TYPE ="button"  VALUE ="JS- Home"  onClick ="location='script.html'" >  
None.gif
< INPUT  TYPE ="button"  VALUE ="Next"  onCLick ="history.forward()" >  
None.gif
FORM >  
None.gif
body >  
None.gif
html >  
None.gif50、查看某网址的源代码 
None.gif把如下代码加入
< body > 区域中 
ExpandedBlockStart.gifContractedBlock.gif
< SCRIPT > dot.gif  
InBlock.gif
function add() 
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif
var ress=document.forms[0].luxiaoqing.value 
InBlock.gifwindow.location
="view-source:"+ress; 
ExpandedBlockEnd.gif}
 
None.gif
SCRIPT >  
None.gif输入要查看源代码的URL地址: 
None.gif
< FORM >< input  type ="text"  name ="luxiaoqing"  size =40  value ="http://" > FORM >  
None.gif
< FORM >< br >  
None.gif
< INPUT  type ="button"  value ="查看源代码"  onClick =add() >  
None.gif
FORM >  
None.gif51、title显示日期 
None.gif把如下代码加入
< body > 区域中: 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript1.2" > dot.gif  
InBlock.gif
 
None.gif
script >  
None.gif52、显示所有链接 
None.gif把如下代码加入
< body > 区域中 
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript1.2" > dot.gif  
InBlock.gif
 
None.gif
script >  
None.gif
< input  type ="button"  onClick ="extractlinks()"  value ="显示所有的连接" >  
None.gif53、回车键换行 
None.gif把如下代码加入
< body > 区域中 
ExpandedBlockStart.gifContractedBlock.gif
< script  type ="text/javascript" > dot.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif
function handleEnter (field, event) dot.gif
InBlock.gif
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; 
ExpandedSubBlockStart.gifContractedSubBlock.gif
if (keyCode == 13dot.gif
InBlock.gif
var i; 
InBlock.gif
for (i = 0; i < field.form.elements.length; i++
InBlock.gif
if (field == field.form.elements) 
InBlock.gif
break
InBlock.gif
= (i + 1% field.form.elements.length; 
InBlock.giffield.form.elements.focus(); 
InBlock.gif
return false
ExpandedSubBlockEnd.gif}
 
InBlock.gif
else 
InBlock.gif
return true
ExpandedBlockEnd.gif}
   
None.gif
script >  
None.gif
< form >  
None.gif
< input  type ="text"  onkeypress ="return handleEnter(this, event)" >< br >  
None.gif
< input  type ="text"  onkeypress ="return handleEnter(this, event)" >< br >  
None.gif
< textarea > 回车换行 
None.gif54、确认后提交 
None.gif把如下代码加入
< body > 区域中 
ExpandedBlockStart.gifContractedBlock.gif
< SCRIPT  LANGUAGE ="javascript" > dot.gif  
InBlock.gif
 
None.gif
SCRIPT >  
None.gif
< form  name ="lnman"  method ="post"  action ="" >  
None.gif
< p >  
None.gif
< input  type ="text"  name ="textfield"  value ="确认后提交" >  
None.gif
p >  
None.gif
< p >  
None.gif
< input  type ="button"  name ="Submit"  value ="提交"  onclick ="msg();" >  
None.gif
p >  
None.gif
form >  
None.gif55、改变表格的内容 
None.gif把如下代码加入
< body > 区域中 
ExpandedBlockStart.gifContractedBlock.gif
< script  language =javascript > dot.gif  
InBlock.gif
var arr=new Array() 
InBlock.gifarr[
0]="一一一一一"
InBlock.gifarr[
1]="二二二二二"
ExpandedBlockEnd.gifarr[
2]="三三三三三"
None.gif
script >  
None.gif
< select  onchange ="zz.cells[this.selectedIndex].innerHTML=arr[this.selectedIndex]" >  
None.gif
< option  value =a > 改变第一格 option >  
None.gif
< option  value =a > 改变第二格 option >  
None.gif
< option  value =a > 改变第三格 option >  
None.gif
select >  
None.gif
< table  id =zz  border =1 >  
None.gif
< tr  height =20 >  
None.gif
< td  width =150 > 第一格 td >  
None.gif
< td  width =150 > 第二格 td >  
None.gif
< td  width =150 > 第三格 td >  
None.gif
tr >  
None.gif
table >
None.gif < script language = " JavaScript " >
None.gif

None.gif
script >
None.gif private   int  WeekOfYear( string  date)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifDateTime curDay 
= Convert.ToDateTime(date);
InBlock.gif
InBlock.gif
int firstdayofweek = Convert.ToInt32(Convert.ToDateTime(curDay.Year.ToString() + "-" + "1-1").DayOfWeek);
InBlock.gif
InBlock.gif
int days = curDay.DayOfYear;
InBlock.gif
int daysOutOneWeek = days - (7 - firstdayofweek);
InBlock.gif
InBlock.gif
if (daysOutOneWeek <= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
return 1;
ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
int weeks = daysOutOneWeek / 7;
InBlock.gif
if (daysOutOneWeek % 7 != 0)
InBlock.gifweeks 
++;
InBlock.gif
InBlock.gif
return weeks + 1;
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/ghd258/archive/2006/11/03/549179.html

你可能感兴趣的:(55种网页常用小技巧(javascript))