天天看點

javaScript經典代碼大全

1. οncοntextmenu="window.event.returnvalue=false" 将徹底屏蔽滑鼠右鍵

<table border οncοntextmenu=return(false)><td>no</table> 可用于Table

2. <body onselectstart="return false"> 取消選取、防止複制

3. οnpaste="return false" 不準粘貼

4. οncοpy="return false;" oncut="return false;" 防止複制

5. <link rel="Shortcut Icon" href="favicon.ico" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" > IE位址欄前換成自己的圖示

6. <link rel="Bookmark" href="favicon.ico" target="_blank" rel="external nofollow" target="_blank" rel="external nofollow" > 可以在收藏夾中顯示出你的圖示

7. <input style="ime-mode:-Disabled"> 關閉輸入法

8. 永遠都會帶着架構

<script language=";http://www.51js.com/`";>

12.删除時确認

<a href=`"确實要删除嗎?"location="boos.asp?&areyou=删除&page=1"`>删

除</a> 

13. 取得控件的絕對位置

//"> 

<param name="Command" value="Minimize"></object>

<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> 

<param name="Command" value="Maximize"></object>

<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">

<PARAM NAME="Command" value="Close"></OBJECT>

<input type=button value=最小化 οnclick=hh1.Click()>

<input type=button value=最大化 οnclick=hh2.Click()>

<input type=button value=關閉 οnclick=hh3.Click()>

本例适用于IE

17.屏蔽功能鍵Shift,Alt,Ctrl 

<script> 

function look(){  

if(event.shiftKey)  

alert("禁止按Shift鍵!"; //可以換成ALT CTRL 

}  

document.οnkeydοwn=look;  

</script> 

18. 網頁不會被緩存 

<META HTTP-EQUIV="pragma" CONTENT="no-cache"> 

<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"> 

<META HTTP-EQUIV="eXPires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT"> 

或者<META HTTP-EQUIV="expires" CONTENT="0"> 

19.怎樣讓表單沒有凹凸感? 

<input type=text style="border:1 solid #000000">  

或 

  <input type=text style="border-left:none; border-right:none; border-top:none; border-bottom:  

1 solid #000000"></textarea> 

20.<div><span>&<layer>的差別?  

<div>(division)用來定義大段的頁面元素,會産生轉行  

<span>用來定義同一行内的元素,跟<div>的唯一差別是不産生轉行  

<layer>是ns的标記,ie不支援,相當于<div> 

21.讓彈出視窗總是在最上面: 

<body οnblur="this.focus();"> 

22.不要滾動條?  

讓豎條沒有:  

<body style=`overflow:-Scroll;overflow-y:hidden`>  

</body>  

讓橫條沒有:  

<body style=`overflow:-Scroll;overflow-x:hidden`>  

</body>  

兩個都去掉?更簡單了  

<body scroll="no">  

</body>  

23.怎樣去掉圖檔連結點選後,圖檔周圍的虛線? 

<a href="#" target="_blank" rel="external nofollow" onFocus="this.blur()"><img src="logo.jpg" border=0></a> 

24.電子郵件處理送出表單 

<form name="form1" method="post" action="mailto***@***.com" enctype="text/plain">  

<input type=submit> 

</form> 

25.在打開的子視窗重新整理父視窗的代碼裡如何寫? 

window.opener.location.reload() 

26.如何設定打開頁面的大小 

<body οnlοad="top.resizeTo(300,200);"> 

打開頁面的位置<body οnlοad="top.moveBy(300,200);"> 

27.在頁面中如何加入不是滿鋪的背景圖檔,拉動頁面時背景圖不動  

<style>  

body  

{; ;  

"; 

autourl[4]="http://www.nuaa.edu.cn/"; 

autourl[5]="http://www.cctv.com/"; 

function butt(){ 

document.write("<form name=autof>" 

for(var i=1;i<autourl.length;i++) 

document.write("<input type=text name=txt"+i+" size=10 value=測試中……> =》<input type=text  

name=url"+i+" size=40> =》<input type=button value=GO  

οnclick=window.open(this.form.url"+i+".value)><br>" 

document.write("<input type=submit value=重新整理></form>" 

butt() 

function auto(url){ 

document.forms[0]["url"+b].value=url 

  if(tim>200) 

{document.forms[0]["txt"+b].value="連結逾時"} 

else 

{document.forms[0]["txt"+b].value="時間"+tim/10+"秒"} 

b++ 

function run(){for(var i=1;i<autourl.length;i++)document.write("<img  

src=http://"+autourl+"/"+Math.random()+" width=1 height=1  

οnerrοr=auto(http://";+autourl+"`)>"} 

run()</script>

37. 各種樣式的光标 

auto :标準光标 

default :标準箭頭 

hand :手形光标 

wait :等待光标 

text :I形光标 

vertical-text :水準I形光标 

no-drop :不可拖動光标 

not-allowed :無效光标 

help :?幫助光标 

all-scroll :三角方向标 

move :移動标 

crosshair :十字标 

e-resize 

n-resize 

nw-resize 

w-resize 

s-resize 

se-resize 

sw-resize 

38.頁面進入和退出的特效 

進入頁面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)"> 

推出頁面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">  

這個是頁面被載入和調出時的一些特效。Duration表示特效的持續時間,以秒為機關。Transition表示使 

用哪種特效,取值為1-23: 

  0 矩形縮小  

  1 矩形擴大  

  2 圓形縮小 

  3 圓形擴大  

  4 下到上重新整理  

  5 上到下重新整理 

  6 左到右重新整理  

  7 右到左重新整理  

  8 豎百葉窗 

  9 橫百葉窗  

  10 錯位橫百葉窗  

  11 錯位豎百葉窗 

  12 點擴散  

  13 左右到中間重新整理  

  14 中間到左右重新整理 

  15 中間到上下 

  16 上下到中間  

  17 右下到左上 

  18 右上到左下  

  19 左上到右下  

  20 左下到右上 

  21 橫條  

  22 豎條  

  23 以上22種随機選擇一種 

39.在規定時間内跳轉 

<META http-equiv=V="REFRESH" content="5;URL=http://www.admin5.com">     40.網頁是否被檢索 

<meta name="ROBOTS" content="屬性值"> 

  其中屬性值有以下一些: 

  屬性值為"all": 檔案将被檢索,且頁上連結可被查詢; 

  屬性值為"none": 檔案不被檢索,而且不查詢頁上的連結; 

  屬性值為"index": 檔案将被檢索; 

  屬性值為"follow": 查詢頁上的連結; 

  屬性值為"noindex": 檔案不檢索,但可被查詢連結; 

  屬性值為"nofollow": 檔案不被檢索,但可查詢頁上的連結。  

繼續閱讀