轉 javascip學習筆記

地址:http://www.blogjava.net/ltc603/archive/2006/08/16/63937.html

1.網頁技術分爲三個方面:靜態網頁、網頁美工、動態網頁。
2.DHTML(動態HTML)是一種通過各種技術的綜合而得以實現的概念,包括三部分:HTML、Script(JavaScrip or VBScript)、CSS(Cascading Style Sheets)。
3.顏色“#rrggbb”六位十六進制數。
4.js刪除提示
1)<a  href="#" οnclick="return(confirm('刪除後無法恢復,您確定刪除嗎?'))">刪除</a>
2)JS
<a  href="#" >刪除</a>
<script language="javascript" type="text/javascript">
function delete_confirm(){
 if(event.srcElement.outerText=="刪除" || event.srcElement.value=="刪除")
  event.returnValue=confirm("刪除後將不能恢復,您確認執行刪除操作麼?");
 }
 document.οnclick=delete_confirm;
</script>

5.點擊按鈕/鏈接彈出提示
1)<input type=button value="reload" οnclick="javascript:reload()">
<script type="text/javascript">
function reload() {
  if (confirm("確認?"))
 {
 var url="#";
 window.location.href=url;
 }
}
2)<a  href="確認後的連接地址" οnclick="return(confirm('想要的提示信息?'))">顯示信息</a>

6.返回主頁/前頁
返回前頁:使用OnClick="history.go(-1)"
返回主頁:使用OnClick='top.location.href="index.jsp"'
<a href="javascript:history.back()">後退</a>
<a href="javascript:history.go()">前進</a>
<a href="javascript:location.reload()">刷新</a>

7.定時關閉網頁
在head區加入
<SCRIPT LANGUAGE="javascript">
setTimeout('window.close();',2000);
</SCRIPT>
表示兩秒後自動關閉窗口。

8. 背景音樂
顯示操作面板:
在相應地方加<embed src="aladdin.mid" width="140" height="35" autostart=true controls="middleconsole">
不顯示操作面板:
在頁中任意地方加<embed src="aladdin.mid" hidden=true autostart=true loop=true>
或<embed src="aladdin.mid" autostart="true" loop="2" width="80" height="30">

9. 如何讓瀏覽器正確顯示word 文件格式?
爲了正確處理word 等格式,你需要在HTML文件中設置好該文件類型
<meta http-equiv="Content-Type" content="application/msword">
還有其它經常設置的文件類型:
application/msword Microsoft Word Document
application/pdf PDF Document
application/wordperfect6.0 WordPerfect 6.0 Document
application/zip ZIP archive
audio/x-wav WAV audio format
audio/midi MIDI audio format
audio/x-pn-realaudio RealAudio
image/gif GIF image format
image/jpeg JPEG image format
image/png PNG image format
text/html HTML document
text/plain Plain text
video/mpeg MPEG video format
video/quicktime QuickTime video format
video/x-msvideo AVI video format

10. 鏈接的不同方式
在幀裏顯示:在鏈接處加target="main"語句,其中main爲幀名
整頁顯示:在鏈接處加target="_top"語句
開新窗口:在鏈接處加target="resource window"語句,如<A HREF="index.htm" TARGET="resource window"></A>

11. 強制主頁每次都不進行緩存,而從服務器上重讀
在Head部分加
<MEAT HTTP-EQUIV="Pragma" CONTENT="no-cache">
這樣一來,瀏覽器將不考慮cacke中的內容而強制重新讀入您的頁面,等於用戶使用Reload。

12. 自動刷新
定時刷新:<META HTTP-EQUIV="Refresh" content="10; URL=http://自己的URL">
幻燈片效果:語句類似上面,但在頁面1中URL指向頁面2,而頁面2指向頁面3 ...
頁面n指回頁面1,即可實現循環顯示頁面的效果

13.提前載入圖片
如果您的站點中後面的頁有大圖形需要顯示,您不妨在第一頁中提前載入。把語句:
<img src="image.jpg" width=0 height=0> ,其中width,height要設置爲0, 放在第一頁HTML中的任何地方。
如果您的訪問者在第一頁停留的時間足夠長,當他進入第二頁時,圖象會立即顯示出來

14. 自動連接
在預定時間後自動連入另一個指定的頁面。
方法:
在<title>...</title>中加入以下一行:
<meta http-equiv="refresh" content="10"; url="otherpage.htm">
其中10代表10秒後自動連接。

15. 移動文字
這在主頁上是常用的,其製作方法很簡單。
<marquee>要移動的文字</marquee>
  1.移動 的方向:<direction=!> !=left, right
  2.移動的方式:<bihavior=!> !=scroll ,side,alternate
  3.循環次數:<loop=!> !=次數。若未指定則循環不止。
  4 循環速度:<scrollamount=!> !=數

16. 浮動背景(背景圖像不滾動 )
當你拉住下拉條時,背景不動。
<body backgroud="#ffff" bgproperties="fixed">
或用CSS樣式表定義:
<style type="text/css">
<!--
body { background-image: url(image/bg.gif); background-attachment: fixed}
-->
</style>

17. 讓背景圖像不平鋪的CSS樣式表定義:
<style type="text/css">
<!--
body { background-image: url(image/bg.gif); background-repeat: no-repeat}
-->
</style>
(不懂)18. 測試瀏覽器類別並自動裝入不同的網頁
目前微軟和網景的瀏覽器並不能完全兼容所有網頁,有的在某種瀏覽器裏非常漂亮,而用其它瀏覽器查看時卻一團糟。如果你需要測試瀏覽器,可以加入以下javascript代碼並保存單獨一個網頁:
<script language="javascript">
function TestBrowser(){
ie = ((navigator.appName ==
"Microsoft Internet Explorer") & &
(parseInt(navigator.appVersion) >= 3 ))
ns = ((navigator.appName == "Netscape") & &
(parseInt(navigator.appVersion) >= 3 ))
if (ns) {
setTimeout(''location.href="nn4.htm"'',10);
} else {
setTimeout(''location.href="ie4.htm"'',10);
}
}
</script>
19. 定義本網頁的關鍵字
在網頁中加入關鍵字,可以供某些搜索站臺機器人的使用,它們會利用該關鍵字爲你的網站做索引,這樣,當別人用關鍵字搜索網站時,如果你的網頁包含該關鍵字,那麼就可以被列出了,定義本網頁關鍵字,可以加入以下代碼:
<meta name="keywords" content="html,dreamweaver,flash,css">
  content 所包含的就是關鍵字,你可以自行設置。
  這裏有個技巧,你可以重複某一個單詞,這樣可以提高自己網站的排行位置,如:
<meta name="keywords" content="dreamweaver,dreamweaver,dreamweaver">
20. 在網頁中加入E-mail鏈接並顯示預定的主題
<a href="mailto:[email protected][email protected]&subject=hello&body=hello">
21. 隱藏在狀態欄裏出現的鏈接信息
當指向一個鏈接時,該鏈接的信息會出現在瀏覽器狀態欄裏,如果需要隱藏信息,可以如下設置:
<a href="http://www.yhyhw.com" onMouseOver="window.status='none';return true">test</a>
  如果想要指向一個鏈接時,瀏覽器狀態欄裏出現特定的信息,把none 改成你需要的文字即可。
22.如何正確使用圖片格式?
目前在網絡上的圖片準標準格式爲JPG和GIF。當圖片顏色數很多時,就選擇JPG,它的壓縮比高,而GIF適合顏色數少的圖片。
23. 如何在網頁上顯示訪問者系統信息?
把以下代碼加入到<Body></Body>:
<script Language="javascript">
document.write(navigator.appVersion)
</script>
24. 如何點擊一個鏈接同時在兩個frame 內變化?
對於一個由topFrame、leftFrame、mainFrame 構成的頁面,如果想在leftFrame 中點擊鏈接,同時在其他兩個frame 內變化,代碼如下:
<a href="x1.htm" οnclick="parent.topFrame.location.href=''x2.htm''" target="mainframe">
25. 打開一個新的瀏覽器窗口並設置窗口的屬性
如果你需要在載入站點的同時,再打開另一個新窗口,加入以下代碼即可:
<script language="javascript">
<!--
var gt = unescape('%3e');
var popup = null;
var over = "Launch Pop-up Navigator";
popup = window.open('', 'popupnav', 'width=160,height=160,resizable=1,
     status=yes,menubar=no,scrollbars=yes');
if (popup != null) {
     if (popup.opener == null) {
          popup.opener = self;
     }
    popup.location.href = 'pop.htm';}
//-->
</script>
期中pop.htm可以設置爲你的htm文件,對於設置新窗口的屬性,對照以下設置:
popup = window.open('', 'popupnav', 'width=200,height=170,resizable=1,scrollbars=auto');
width:寬,height:高,resizable:是否允許訪客縮放新窗口,scrollbars:如果文本超過一屏,是否生成滾動條,status:是否顯示狀態欄,menubar:是否顯示菜單,location:是否顯示地址欄.
以上所有屬性使用格式爲:屬性=yes或者no.而width和height兩個屬性爲:width=#pixels,height=#pixels.
26. 打印按鈕
<form>
<input name="Print" onClick="window.print();
return false" type="button" value="Print">
</form>
27. 查看源碼按鈕
<input type=button name="view" value="查看源碼" onClick=''window.location="view-source:" +window.location.href'' style="font-size:9pt">
28. 如何去掉頁面滾動條?
在body 中加入樣式表控制,代碼如下:
<body bgcolor="#000000" leftmargin="0" topmargin="0"
style="overflow-x: hidden; overflow-y: hidden; width: 100%">
29. 如何讓站點自動跳轉到另一頁?
加入以下代碼到HTML文件中即可:
<meta http-equiv="refresh" content="5;url=http://www.yhyhw.com/">
content中的"5"爲停留的秒數,http://www.yhyhw.com/ 是將要跳轉的頁面。
30. 水平線、垂直線
插入HR很簡單:<hr size="1">。如何讓它垂直呢,更簡單:<hr size="100" width="1">
31. 如何讓下拉式菜單中的鏈接來打開一個新的窗口?
先把下拉式菜單設置好,如:
<form method="POST">
<select name="D1" size="1">
<option value="http://www.163.com/">網易</option>
<option value="http://www.suho.com/">搜狐</option></select>
<input type="submit" value="確定" name="B1"><input type="reset" value="重置"name="B2"></p></form>
然後把<select name="D1" size="1">改爲
<select onChange="javascript:window.open(this.options[this.selectedIndex].value)">即可。
32. 如何讓下拉式菜單中的鏈接來打開一個新的窗口?
先把下拉式菜單設置好,如:
<form method="POST">
<select name="D1" size="1">
<option value="http://www.163.com/">網易</option>
<option value="http://www.suho.com/">搜狐</option></select>
<input type="submit" value="確定" name="B1"><input type="reset" value="重置"name="B2"></p></form>
然後把<select name="D1" size="1">改爲
<select onChange="javascript:window.open(this.options[this.selectedIndex].value)">即可。

34. 如何跳到頁面的頂部?
當瀏覽者瀏覽到頁面底部後,你需要提供一個單擊,讓瀏覽者方便的跳到頁面頂部,加入以下代碼:
<a href="#top">返回頂部</a>
35.如何讓瀏覽器正確顯示word文件格式?
爲了正確處理word等格式,你需要在HTML文件中設置好該文件類型,比如:
<meta http-equiv="Content-Type" content="Application/msword">
還有其它經常設置的文件類型:
Application/msword Microsoft Word Document application/pdf PDF Documentapplication/wordperfect6.0 WordPerfect 6.0 Documentapplication/zip ZIP archiveaudio/x-wav WAV audio formataudio/midi MIDI audio formataudio/x-pn-realaudio RealAudioimage/gif GIF image formatimage/jpeg JPEG image formatimage/png PNG image formattext/html HTML documenttext/plain Plain textvideo/mpeg MPEG video formatvideo/quicktime QuickTime video formatvideo/x-msvideo AVI video format
36.如何在一個站點不同頁面間播放同一種聲文件?
大家有這樣的經驗,當你訪問一個站點首頁時,會聽到該頁設置的背景聲音文件,比如一段音樂。當你鏈接到該站點另一頁時,音樂就停止了。如何讓聲音不斷呢。其實,你只需要建立一個上下框架結構的網頁,把聲音文件建立在下框架裏,並把下框架的寬度設置爲一個像素,而上框架裏是頁面內容,當訪問者離開站點首頁時,因下框架內容未變,所以,聲音不會間斷。大家還要注意兩點,第一,把框架的邊框設置爲0;第二,隱藏聲音文件的播放界面,然後把上下兩個框架的背景設置爲相同。
37.如何讓所有頁面共享同一個層疊樣式表(CSS)?
在每一個頁面的<HEAD></HEAD>部分中加入以下代碼:
<link rel="stylesheet" Type="text/css" href="cnshell.css">
其中cnshell.css爲共享的層疊樣式表文件
38.如何爲鏈接定製新窗口?
我們可以打開一個新的窗口來顯示鏈接的內容,但如何定製這個新窗口呢。
只需要在標籤<A>中加入onClick事件:
<a href="#" onClick="window.open('cnshell.htm','help','scrollbars=yes,
resizable=yes,width=500,height=40')">問答</a>
"#"表示單擊鏈接"問答"後,當前窗口保持不變,cnshell.htm爲單擊鏈接"問答"後所打開新窗口裝載的內容,而scrollbars=yes,resizable=yes,width=500,height=40爲設置新窗口的大小等屬性。
39. 如何在頁面利用單擊來關閉瀏覽窗口?
在<BODY></BODY>部分加入以下代碼:
<a href="javascript:window.close()">關閉窗口</a>
40. 如何刪除圖片鏈接的藍色邊框?
如果我們設置了圖片爲一個鏈接,會發現圖片四周出現了藍色邊框。要刪除邊框,需要在圖片標籤里加上border="0"。如:<img src="dog.jpg" border="0">
41. 如何清除頁面中的框架結構?
在鏈接屬性中加入target="_top" 如下設置:
<a href="http://www.yufeng21.com" target="_top">宇風多媒體</a>
當你單擊了這個鏈接,頁面所有框架被清除並以該鏈接內容替代。
42.直接跳轉到下一頁面
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>
後加入下面語句,表示跳轉到Config.do
<meta http-equiv="refresh" content="0;url=Config.do" />
43. 如何創建一個下拉菜單?
我們在主頁中常會用到下拉菜單,一般來說,它需要CGI程序支持。你也可以利用javascript編寫一個。
<head>
<script LANGUAGE="javascript">function formHandler(){var URL = document.form.site.options[document.form.site.selectedIndex]
.value;window.location.href = URL;}
</script>
</head>
<body>
<form name="form"><select NAME="site" SIZE="1" onChange="formHandler()"><option value="請選擇">請選擇</option><option value="http://www.yufeng21.com/">分欄內容</option><option value="http://www.yufeng21.com/">分欄內容</option><option value="http://www.yufeng21.com/">分欄內容</option><option value="[email protected]">給我寫信</option></select></form>
</body>
44.如何建立一個站點的搜索引擎系統?
如果你的站點有許多內容,你希望訪問者能很快找到他想要的信息。那麼你需要建立一個搜索引擎。連接到網站網絡特區http://netzone.swatou.com/personal/,單擊"申請站點引擎"並填寫申請表,再按照要求建立站點頁面數據庫即可。
45. 什麼是目標窗口,它該如何設置?
目標窗口是頁面鏈接所指內容顯示的窗口,也就是當你單擊了頁面某一個鏈接後,該鏈接所指的內容在那個窗口顯示。大多數情況下,我們無需關心它,因爲一般都是在同一窗口顯示。target是鏈接標籤<a>的屬性,它的作用就是指定目標窗口,target有以下幾個值:
_self-將鏈接指向的內容裝載到當前頁的窗口或框架中
_top-完全取代當前頁面的所有框架
_blank-爲鏈接指向的內容打開一個新的窗口
_parent-把鏈接指向的內容裝入當前頁<FRAMESET>父窗口中
以上設置多用在框架結構的頁面中。
46. 如何爲所有鏈接指定同一目標窗口?
在框架網頁結構中,我們需要指定鏈接所指向的內容顯示在那個窗口中。如果你的鏈接大部分都指定到同一個窗口中,就可以在<HEAD></HEAD>部分中加入:<base target="窗口名">,你無需爲每個鏈接再指定窗口了。
47. 儘量用table標籤,這樣可以避免<td>之間的干擾;<table>儘量設爲<table width="100%" border="0" cellpadding="0" ellspacing="0">,一方面是不顯示錶格線,另一方面佔滿整個寬度,不會因爲內容不夠而寬度變窄;包含<table>的 <td>要設爲<td valign="top">,不然內部table默認居中。
48.<table>中第一行表格的width控制各列寬度;每列第一個格的height控制各行高度。
49.如何把一行表單或圖片都放於middle位置:要把每一個都用<td>隔開,每個<td>都要設valign="middle"。
50.<td></td>之間不要有空格或空行,即應該<td><img src="***"></td>這麼寫,否則圖片上下會產生空白的一細條。
51.&nbsp;表示一個空格,這個空格佔一個字符(對於字母)還是兩個字符(對於漢字)是根據瀏覽器的(工具->Internet選項->語言)來決定的,是不確定的,所以中文開頭只需要兩個&nbsp;而不是四個&nbsp;。
52.在線播放:
下面兩個視頻,前一個是RM視頻(.rm .rmvb),後一個是MP視頻(.wmv .asf .avi),爲了不影響大家,都設置爲手動播放,並將相關的代碼及說明放在了視頻的下面:
RM源代碼:
<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=352 height=288>
<PARAM NAME=SRC VALUE="http://www.cqie.cn/pub/iec.rm">
<PARAM NAME=CONSOLE VALUE="http://www.cqie.cn/pub/iec.rm">
<PARAM NAME=CONTROLS VALUE=imagewindow>
<PARAM NAME=AUTOSTART VALUE=0 >
</OBJECT>
<br>
<OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id="video" width=352>
<PARAM NAME=SRC VALUE="http://www.cqie.cn/pub/iec.rm">
<PARAM NAME=AUTOSTART VALUE=0>
<PARAM NAME=CONTROLS VALUE=controlpanel>
<PARAM NAME=CONSOLE VALUE="http://www.cqie.cn/pub/iec.rm">
</OBJECT>
說明:以後可以直接把以上代碼放到網頁中使用,需要修改的屬性說明如下width=352 height=288 這是控制媒體高度和寬度的VALUE="http://www.cqie.cn/pub/iec.rm" 這是指定媒體文件URL地址的,如果安裝了REALSERVER的話,可以用rtsp://www.cqie.cn/pub/iec.rm來進行流式播放,看起來會更流暢,而且可拖動。AUTOSTART VALUE=0  這是控制是否自動播放的,你只要將value=1就可以自動播放了

MP源代碼:
<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=160 height=168 >
<PARAM NAME=AUTOSTART VALUE=0 >
<param name=ShowStatusBar value=-1>
<param name=Filename value=http://xiaoping.cqie.cn/wmv/jler.wmv>
<embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src="http://xiaoping.cqie.cn/wmv/jler.wmv" width=160 height=168>
</embed>
</object>

53.樹狀顯示js代碼
(要求:某行文本前面有一個加號的標籤,一點擊加號變成減號,同時該行展開它之下所屬信息,以縮進形式呈現,再點擊減號又變回加號、下面展開的文本收回,這應該怎麼做?除了js方式有什麼其他方式實現麼?謝謝!)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
<script language="javascript">
function showLay(divId){
        var objDiv = eval(divId);
        if (objDiv.style.display=="none"){
                eval("sp"+divId+".innerHTML='-'");
                objDiv.style.display="";
        }else{
                eval("sp"+divId+".innerHTML='+'");
                objDiv.style.display="none";
        }}
</script>
</head>
<body>
<a href="#" οnclick="showLay('Layer1')"><span id="spLayer1">+</span>a</a><br>
<div id="Layer1" style="display:none;">
|-<a href="insert_unit_info.html" target="body">a1</a><br>
|-<a href="select_unit_info.jsp" target="body">a2</a><br>
</div>
<a href="#" οnclick="showLay('Layer2')"><span id="spLayer2">+</span>b</a><BR>
<div id="Layer2" style="display:none;">
|-<a href="insert_item_info.html" target="body">b1</a><br>
|-<a href="select_item_info.jsp" target="body">b2</a><br>
</div>
<a href="#" οnclick="showLay('Layer3')"><span id="spLayer3">+</span>c</a><BR>
<div id="Layer3" style="display:none;">
|-<a href="insert_expert_info.html" target="body">c1</a><br>
|-<a href="select_expert_info.jsp" target="body">c2</a><br>
</div>
<a href="#" οnclick="showLay('Layer4')"><span id="spLayer4">+</span>d</a><BR>
<div id="Layer4" style="display:none;">
|-d1<br>
|-d2<br>
</div>
</body>
</html>

54.下拉菜單(新建個.html文件,把代碼考進去就行)
<html>
<head>
<title>打造下拉菜單</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; οnresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
</script>
</head>
<body bgcolor="#CCCCCC" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll=auto>
<div id="title" style="position:absolute; left:8px; top:15px; width:240px; height:15px; z-index:1; background-color: #006699;
layer-background-color: #006699; border: 1px none #000000">
  <table width="480" cellspacing="0" cellpadding="2">
    <tr>
      <td width="120" onMouseOver="MM_showHideLayers('menu1','','show')" onMouseOut="MM_showHideLayers
('menu1','','hide')"><b><font color="#FFFFFF"><a href="#">■
        經典論壇</a></font></b> </td>
    </tr>
  </table>
</div>
<div id="menu1" style="position:absolute; left:8px; top:34px; width:120px; height:80px; z-index:2; background-color: #999966;
layer-background-color: #999966; border: 1px none #000000; visibility: hidden" onMouseOver="MM_showHideLayers
('menu1','','show')" onMouseOut="MM_showHideLayers('menu1','','hide')">
  <table width="100%" cellspacing="0" cellpadding="2" height="80">
    <tr>
      <td>&nbsp;<a href="#">Dreamweaver 專欄</a></td>
    </tr>
    <tr>
      <td>&nbsp;<a href="#">Fireworks 專欄</a></td>
    </tr>
    <tr>
      <td>&nbsp;<a href="#">Flash 基本操作</a></td>
    </tr>
    <tr>
      <td>&nbsp;<a href="#">Flash 5 Action</a></td>
    </tr>
  </table>
</div>
</body>
</html>

55.防止下載網頁信息(例如顯示受控文件)的簡單方法:
a。屏蔽鼠標左右鍵,<body οncοntextmenu=self.event.returnValue=false onselectstart="return false">
b。加密網頁源文件,推薦Batch Html Encryptor加密軟件。
c.用Adobe Acrobat 6.0 Standard軟件加密。
 
55。此方法顯示下拉框默認值

<select name="max">
 <option value="1">第一名</option>
 <option value="2">第二名</option>
 <option value="3">第三名</option>
</select>
<script>document.all("max").value="3"</script>

56.用javascript設置輸入框焦點
<html>
<head>
<script language="javascript">
function t() {
document.getElementById('aa').focus(); 
}                           <!--設置id爲aa的元素得到焦點-->
</script>
</head>
<body οnlοad="javascript:t()">
<input type="text" id="aa"> <!--設置文本輸入框的id爲aa-->
</body>
</html>

57.select標籤下的OPTION標籤沒有value屬性時,把內容當屬性傳過去,比如<OPTION>所有用戶</OPTION>傳的值就是所有用戶,建議用以下方法。
<select name="account.accountId" >
    <OPTION value="">所有日誌</OPTION>
    <OPTION value="renyang">任楊</OPTION>
</select>

58.不保留緩存方法:
<%
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "must-revalidate");
response.setDateHeader("Expires",0);
%>

59.全選、全不選js方法 (直接放在.htm文件中即可)
<SCRIPT language="javascript">
function checkAll(e, itemName)
{
  var aa = document.getElementsByName(itemName);
  for (var i=0; i<aa.length; i++)
   aa[i].checked = e.checked;
}
function check(e, allName)
{
  var all = document.getElementsByName(allName)[0];
  if(!e.checked) all.checked = false;
  else
  {
    var aa = document.getElementsByName(e.name);
    for (var i=0; i<aa.length; i++)
     if(!aa[i].checked) return;
    all.checked = true;
  }
}
</SCRIPT>
<input type=checkbox name=allPersons id=allPersons οnclick="checkAll(this, 'persons')">&nbsp;<label for="allPersons">全選</label><br>
<input type="checkbox" name="persons" id=persons value="1">&nbsp;<label for="persons">第一名</label><br>
<input type="checkbox" name="persons" id=persons value="2">&nbsp;<label for="persons">第二名</label><br>
<!-- 問題:第一名和第二名這兩個字ID不能一樣,否則點第二名這三個字時第一名前的框變化 -->  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章