WEB編程開發(fā)常用的代碼 (zhuan)
WEB編程開發(fā)常用的代碼字體大小:
![]() ![]() ![]() 1. ASP與Access數(shù)據(jù)庫連接: dim conn,mdbfile mdbfile=server.mappath("數(shù)據(jù)庫名稱.mdb") set conn=server.createobject("adodb.connection") 'conn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=數(shù)據(jù)庫密碼;dbq="&mdbfile conn.open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & mdbfile 2. ASP與SQL數(shù)據(jù)庫連接: dim conn set conn=server.createobject("ADODB.connection") con.open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL服務(wù)器名稱或IP地址;UID=sa;PWD=數(shù)據(jù)庫密碼;DATABASE=數(shù)據(jù)庫名稱;" 建立記錄集對象: set rs=server.createobject("adodb.recordset") rs.open SQL語句,conn,3,2 SQL常用命令使用方法: 數(shù)據(jù)記錄篩選: sql="select * from 數(shù)據(jù)表 where 字段名=字段值 order by 字段名 " sql="select * from 數(shù)據(jù)表 where 字段名 like ‘%字段值%‘ order by 字段名 " sql="select top 10 * from 數(shù)據(jù)表 where 字段名 order by 字段名 " sql="select * from 數(shù)據(jù)表 where 字段名 in (‘值1‘,‘值2‘,‘值3‘)" sql="select * from 數(shù)據(jù)表 where 字段名 between 值1 and 值2" 更新數(shù)據(jù)記錄: sql="update 數(shù)據(jù)表 set 字段名=字段值 where 條件表達(dá)式" sql="update 數(shù)據(jù)表 set 字段1=值1,字段2=值2 …… 字段n=值n where 條件表達(dá)式" 刪除數(shù)據(jù)記錄: sql="delete from 數(shù)據(jù)表 where 條件表達(dá)式" sql="delete from 數(shù)據(jù)表" (將數(shù)據(jù)表所有記錄刪除) 添加數(shù)據(jù)記錄: sql="insert into 數(shù)據(jù)表 (字段1,字段2,字段3 …) valuess (值1,值2,值3 …)" sql="insert into 目標(biāo)數(shù)據(jù)表 select * from 源數(shù)據(jù)表" (把源數(shù)據(jù)表的記錄添加到目標(biāo)數(shù)據(jù)表) 數(shù)據(jù)記錄統(tǒng)計(jì)函數(shù): AVG(字段名) 得出一個表格欄平均值 COUNT(*|字段名) 對數(shù)據(jù)行數(shù)的統(tǒng)計(jì)或?qū)δ骋粰谟兄档臄?shù)據(jù)行數(shù)統(tǒng)計(jì) MAX(字段名) 取得一個表格欄最大的值 MIN(字段名) 取得一個表格欄最小的值 SUM(字段名) 把數(shù)據(jù)欄的值相加 引用以上函數(shù)的方法: sql="select sum(字段名) as 別名 from 數(shù)據(jù)表 where 條件表達(dá)式" set rs=conn.excute(sql) 用 rs("別名") 獲取統(tǒng)的計(jì)值,其它函數(shù)運(yùn)用同上。 數(shù)據(jù)表的建立和刪除: Create TABLE 數(shù)據(jù)表名稱(字段1 類型1(長度),字段2 類型2(長度) …… ) 例:Create TABLE tab01(name varchar(50),datetime default now()) Drop TABLE 數(shù)據(jù)表名稱 (永久性刪除一個數(shù)據(jù)表) 記錄集對象的方法: rs.movenext 將記錄指針從當(dāng)前的位置向下移一行 rs.moveprevious 將記錄指針從當(dāng)前的位置向上移一行 rs.movefirst 將記錄指針移到數(shù)據(jù)表第一行 rs.movelast 將記錄指針移到數(shù)據(jù)表最后一行 rs.absoluteposition=N 將記錄指針移到數(shù)據(jù)表第N行 rs.absolutepage=N 將記錄指針移到第N頁的第一行 rs.pagesize=N 設(shè)置每頁為N條記錄 rs.pagecount 根據(jù) pagesize 的設(shè)置返回總頁數(shù) rs.recordcount 返回記錄總數(shù) rs.bof 返回記錄指針是否超出數(shù)據(jù)表首端,true表示是,false為否 rs.eof 返回記錄指針是否超出數(shù)據(jù)表末端,true表示是,false為否 rs.delete 刪除當(dāng)前記錄,但記錄指針不會向下移動 rs.addnew 添加記錄到數(shù)據(jù)表末端 rs.update 更新數(shù)據(jù)表記錄 判斷所填數(shù)據(jù)是數(shù)字型 if not isNumeric(request("字段名稱")) then response.write "不是數(shù)字" else response.write "數(shù)字" end if 頁面執(zhí)行時間: <%startime = Timer()%> .... .... 內(nèi)容 ... ... 結(jié)尾 <% Dim Endtime Endtime = Timer() response.write "頁面執(zhí)行時間:<font color=red>"&FormatNumber((Endtime-Startime)*1000,5)&"</font> 毫秒" %> 定義打開網(wǎng)頁時起始窗口的大小 <script for="window" event="onload"> window.resizeTo(500,300) </script> 隨機(jī)數(shù): <%randomize%> <%=(int(rnd()*n)+1)%> 查詢數(shù)據(jù)時得到的記錄關(guān)鍵字用紅色顯示: replace(RS("字段X"),searchname,"<font color=#FF0000>" & searchname & "</font>") 通過asp的手段來檢查來訪者是否用了代理 <% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then response.write "<font color=#FF0000>您通過了代理服務(wù)器,"& _ "真實(shí)的IP為"&Request.ServerVariables("HTTP_X_FORWARDED_FOR") end if %> 判斷上一頁的來源 request.servervariables("HTTP_REFERER") javascript: document.referrer 清除緩存,重新加載頁面 <%response.expires = 0 response.expiresabsolute = now() - 1 response.addHeader "pragma","no-cache" response.addHeader "cache-control","private" Response.cachecontrol = "no-cache" %> 檢索并刪除數(shù)據(jù)庫里的重復(fù)記錄 conn.execute("delete from table where id not in (select distinct from table)") 文件刪除函數(shù) <% '文件刪除函數(shù) function deletefile(filename) if filename<>"" then set fso=server.CreateObject("scripting.filesystemobject") if fso.FileExists(filename) then fso.DeleteFile filename else Response.Write "<script>alert(’該文件不存在’);</script>" end if end if end function strfile=server.MapPath("fileName") deletefile(strfile) %> ASP字?jǐn)?shù)計(jì)算函數(shù) <% Function WordCount(strInput) Dim strTemp strTemp = Replace(strInput, vbTab, " ") strTemp = Replace(strTemp, vbCr, " ") strTemp = Replace(strTemp, vbLf, " ") ' 刪除字首字尾空格 strTemp = Trim(strTemp) ' 替換為一個空格 Do While InStr(1, strTemp, " ", 1) <> 0 strTemp = Replace(strTemp, " ", " ") Loop WordCount = UBound(Split(strTemp, " ", -1, 1)) +1 End Function %> 全正則的檢測IP是否合法的函數(shù) function checkIP2(sIPAddress) { var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/; var reg = sIPAddress.match(exp); var ErrMsg="你輸入的是一個非法的IP地址段!\nIP段為::xxx.xxx.xxx.xxx(xxx為0-255)!" var Msg="你輸入的是一個合法的IP地址段!" if(reg==null) { alert(ErrMsg); } else { alert(reg); } } 關(guān)閉子窗口時刷新父窗口 在子窗口 <script language="javascript"> window.opener.location="父窗口頁面" window.close() </script> 文本框輸入限制: <script> function regInput(obj, reg, inputStr) { var docSel = document.selection.createRange() if (docSel.parentElement().tagName != "INPUT") return false oSel = docSel.duplicate() oSel.text = "" var srcRange = obj.createTextRange() oSel.setEndPoint("StartToStart", srcRange) var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length) return reg.test(str) } </script> 小寫英文:<xmp style= "display:inline"> </xmp> <input onkeypress = "return regInput(this, /^[a-z]*$/, String.fromCharCode(event.keyCode))" onpaste = "return regInput(this, /^[a-z]*$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^[a-z]*$/, event.dataTransfer.getData('Text'))" style="ime-mode:Disabled" ><br> 大寫英文:<xmp style= "display:inline"> </xmp> <input onkeypress = "return regInput(this, /^[A-Z]*$/, String.fromCharCode(event.keyCode))" onpaste = "return regInput(this, /^[A-Z]*$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^[A-Z]*$/, event.dataTransfer.getData('Text'))" style="ime-mode:Disabled"> <br> 任意數(shù)字:<xmp style="display:inline"> </xmp> <input onkeypress = "return regInput(this, /^[0-9]*$/, String.fromCharCode(event.keyCode))" onpaste = "return regInput(this, /^[0-9]*$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^[0-9]*$/, event.dataTransfer.getData('Text'))" style="ime-mode:Disabled" ><br> 限2位小數(shù):<xmp style="display:inline"> </xmp> <input onkeypress = "return regInput(this, /^\d*\.?\d{0,2}$/, String.fromCharCode(event.keyCode))" onpaste = "return regInput(this, /^\d*\.?\d{0,2}$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^\d*\.?\d{0,2}$/, event.dataTransfer.getData('Text'))" style="ime-mode:Disabled" > 如: 123.12<br> 日 期:<xmp style="display:inline"> </xmp> <input onkeypress = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/, String.fromCharCode(event.keyCode))" onpaste = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/, event.dataTransfer.getData('Text'))" style="ime-mode:Disabled" > 如: 2002-9-29<br> 任意中文:<xmp style="display:inline"> </xmp> <input onkeypress = "return regInput(this, /^$/, String.fromCharCode(event.keyCode))" onpaste = "return regInput(this, /^[\u4E00-\u9FA5]*$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^[\u4E00-\u9FA5]*$/, event.dataTransfer.getData('Text'))" ><br> 部分英文:<xmp style="display:inline"> </xmp> <input onkeypress = "return regInput(this, /^[a-e]*$/, String.fromCharCode(event.keyCode))" onpaste = "return regInput(this, /^[a-e]*$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^[a-e]*$/, event.dataTransfer.getData('Text'))" style="ime-mode:Disabled" > 范圍: a,b,c,d,e<br> 部分中文:<xmp style="display:inline"> </xmp> <script language=javascript> function checkChinese(oldLength, obj) { var oTR = window.document.selection.createRange() var reg = /[^一二三四五六七***十]/g oTR.moveStart("character", -1*(obj.value.length-oldLength)) oTR.text = oTR.text.replace(reg, "") } </script> <input onkeypress="return false" onkeydown="setTimeout('checkChinese('+this.value.length+','+this.uniqueID+')', 1)" onpaste = "return regInput(this, /^[一二三四五六七***十]*$/, window.clipboardData.getData('Text'))" ondrop = "return regInput(this, /^[一二三四五六七***十]*$/, event.dataTransfer.getData('Text'))" > 范圍: 一二三四五六七***十<br> [Ctrl+A 全選 Ctrl+C 復(fù)制] 不能點(diǎn)右鍵,不用CTRL+A,不能復(fù)制作! <body oncontextmenu="window.event.returnValue=false" onkeypress="window.event.returnValue=false" onkeydown="window.event.returnValue=false" onkeyup="window.event.returnValue=false" ondragstart="window.event.returnValue=false" onselectstart="event.returnValue=false"> </body> 顯示狀態(tài)攔固定文字: 放在body前 <base onmouseover="window.status='這里是Goaler的Blog系統(tǒng),歡迎訪問';return true"> 用鍵盤打開網(wǎng)頁 <script language=javascript> document.onkeydown=gopage var add="Admin/AddArticle.asp" var logon="Admin/Logon.asp" function gopage() { if (event.keyCode==13) location=add if (event.keyCode==38) location=logon } </script> 根據(jù)內(nèi)容自動調(diào)整iframe高度 有時為了方便使用Iframe,但被潛入的頁面長度不是固定的,顯示滾動條不僅影響美觀還對用戶操作帶來不便,自動調(diào)整高度可以解決這個問題。^_^ function f_frameStyleResize(targObj) { var targWin = targObj.parent.document.all[targObj.name]; if(targWin != null) { var HeightValue = targObj.document.body.scrollHeight if(HeightValue < 600){HeightValue = 600} //不小于600 targWin.style.pixelHeight = HeightValue; } } function f_iframeResize() { bLoadComplete = true; f_frameStyleResize(self); } var bLoadComplete = false; window.onload = f_iframeResize; 禁止頁面正文內(nèi)容被選取 <body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()"> 消除ie6自動出現(xiàn)的圖像工具欄,設(shè)置 GALLERYIMG屬性為false或no . <IMG SRC="mypicture.jpg" HEIGHT="100px" WIDTH="100px" GALLERYIMG="no"> 防止點(diǎn)擊空鏈接時,頁面往往重置到頁首端。 代碼“javascript:void(null)”代替原來的“#”標(biāo)記 如何避免別人把你的網(wǎng)頁放在框架中 <script language=“javascript”><!--if (self!=top){top.location=self.location;} -->< /script> 頁面定時刷新 <meta http-equiv="Refresh" content="秒" > 頁面定時轉(zhuǎn)向新的地址 <meta http-equiv="refresh" content="秒;URL=url"> 關(guān)閉窗口,這個是不會彈出提示直接關(guān)的: 把如下代碼加入<body>區(qū)域中 <OBJECT id=closes type="application/x-oleobject" classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"> <param name="Command" value="Close"> </object> <script language="JavaScript">function shutwin(){closes.Click();return;}</script> <a href="javascript:shutwin();">關(guān)閉本窗口</a> 有時候好不容易寫出來的程序代碼被別人抄去,心里一定不好受。這還是小事,但如果在我們的源代碼中有一些不希望讓別人知道的內(nèi)容,比如密碼、Action的指向等,這些一旦被人利用,那后果有時是不堪設(shè)想的。而網(wǎng)頁加密就是我們現(xiàn)在需要解決的問題。下面就我在網(wǎng)頁制作中的一些經(jīng)驗(yàn)向大家介紹一些簡單的防范方法。 禁止右鍵 看到這里大家一定會想,這招有很多人介紹過了,而且破解的方法也有很多。但我這里要說的是另一種方法,而且我試了很多方法都沒有能破解。具體如下: <html> <head> <script> function stop(){ alert("試試能破解嗎?"); return false; } document.oncontextmenu=stop; </script> <boyd>你可以按右鍵、shift+F10和右ctrl左邊的那個鍵試試!看能不能解。^_^</body> 大家試試,看能不能破解!你可以將alert("試試能破解嗎?");這句去掉,這樣當(dāng)按右鍵時就什么反應(yīng)也沒有了,就好像沒有右鍵功能一樣。 禁示查看源代碼 我們已經(jīng)禁了右鍵,但從"查看"菜單下的"源文件"中同樣可以看到源代碼,下面我們就來解決這個問題: 其實(shí)這只要使用一個含有<frame></frame>標(biāo)記的網(wǎng)頁便可以達(dá)到目的。 <frameset> <frame src="你要保密的文件的URL"> </frameset> 這樣當(dāng)有人使用"查看"下的"源文件"的時候,看到的將是上面的那段代碼,而你真正的文件又躲過一劫。 禁示另存為 通過上面的兩步好像你的源代碼已經(jīng)安全了,但別忘了,別人還可以將你的頁面保存下來,再慢慢分析。不過別擔(dān)心,下面我們來解決這個問題。 在你要保密的網(wǎng)頁中加入以下代碼: <noscript><iframe src="/*.htm"></iframe></noscript> 徹底屏蔽右鍵方法。 <body oncontextmenu="return false"> 雙擊頁面后自動滾屏,單擊后停止。 <SCRIPT language=JavaScript> var currentpos,timer; function initialize() { timer=setInterval("scrollwindow()",16); } function sc(){ clearInterval(timer); } function scrollwindow() {currentpos=document.body.scrollTop; window.scroll(0,++currentpos); if (currentpos != document.body.scrollTop) sc(); } document.onmousedown=sc document.ondblclick=initialize </script> 設(shè)定腳本出錯能繼續(xù)運(yùn)行 <script language="javascript"> function KillError() { return false; } window.onerror=KillError; </script> 將徹底屏蔽鼠標(biāo)右鍵 oncontextmenu="window.event.returnvalue=false" 可用于Table <table border oncontextmenu=return(false)><td>no</table> 取消選取、防止復(fù)制 <body onselectstart="return false"> 不準(zhǔn)粘貼 onpaste="return false" 防止復(fù)制 oncopy="return false;" oncut="return false;" IE地址欄前換成自己的圖標(biāo) <link rel="Shortcut Icon" href="favicon.ico"> 可以在收藏夾中顯示出你的圖標(biāo) <link rel="Bookmark" href="favicon.ico"> 關(guān)閉輸入法 <input style="ime-mode:disabled"> 永遠(yuǎn)都會帶著框架 <script language="javascript"><!-- if (window == top)top.location.href = "frames.htm"; //frames.htm為框架網(wǎng)頁 // --> </script> 防止被人frame <SCRIPT LANGUAGE=javascript><!-- if (top.location != self.location) top.location=self.location; // --> </SCRIPT> 怎樣通過asp的手段來檢查來訪者是否用了代理 <% if Request.ServerVariables("HTTP_X_FORWARDED_FOR")<>"" then response.write "<font color=#FF0000>您通過了代理服務(wù)器," & "真實(shí)的IP為 "&Request.ServerVariables("HTTP_X_FORWARDED_FOR") end if %> 取得控件的絕對位置 //javascript <script language="javascript"> function getIE(e){ var t=e.offsetTop; var l=e.offsetLeft; while(e=e.offsetParent){ t+=e.offsetTop; l+=e.offsetLeft; } alert("top="+t+"nleft="+l); } </script> //VBScript <script language="VBScript"> <!-- function getIE() dim t,l,a,b set a=document.all.img1 t=document.all.img1.offsetTop l=document.all.img1.offsetLeft while a.tagName<>"BODY" set a = a.offsetParent t=t+a.offsetTop l=l+a.offsetLeft wend msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置" end function --> </script> 光標(biāo)是停在文本框文字的最后 <script language="javascript"> function cc() { var e = event.srcElement; var r =e.createTextRange(); r.moveStart('character',e.value.length); r.collapse(true); r.select(); } </script> <input type=text name=text1 value="123" onfocus="cc()"> 判斷上一頁的來源 asp: request.servervariables("HTTP_REFERER") javascript: document.referrer 最小化、最大化、關(guān)閉窗口 <object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11"> <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=最小化 onclick=hh1.Click()> <input type=button value=最大化 onclick=hh2.Click()> <input type=button value=關(guān)閉 onclick=hh3.Click()> 本例適用于IE 記錄并顯示網(wǎng)頁的最后修改時間 <script language=JavaScript> document.write("最后更新時間: " + document.lastModified + "") </script> 2秒后關(guān)閉當(dāng)前頁 <script language="JavaScript"> <!-- setTimeout('window.close();',2000); --> </script> 2秒后載入指定網(wǎng)頁 <head> <meta http-equiv="refresh" content="2;URL=http://你的網(wǎng)址"> </head> 添加到收藏夾 <Script Language="JavaScript"> function bookmarkit() { window.external.addFavorite('http://你的網(wǎng)址','你的網(wǎng)站名稱') } if (document.all)document.write('<a href="#" onClick="bookmarkit()">加入收藏夾</a>') </Script> 禁止鼠標(biāo)右鍵的動作 <Script Language = "JavaScript"> function click() { if (event.button==2||event.button==3) { alert('禁止鼠標(biāo)右鍵'); } document.onmousedown=click // --> </Script> 或 <script language="JavaScript"> function click() { if (event.button==2) {alert('*^_^*'); } } document.onmousedown=click // --> </script> 設(shè)置該頁為首頁 <body bgcolor="#FFFFFF" text="#000000"> <a class="chlnk" style="cursor:hand" HREF onClick="this.style.behavior='url(#default#homepage)'; this.setHomePage('你的網(wǎng)站名稱);"><font color="000000" size="2" face="宋體">設(shè)為首頁</font></a> </body> 節(jié)日倒計(jì)時 <Script Language="JavaScript"> var timedate= new Date("October 1,2002"); var times="國慶節(jié)"; var now = new Date(); var date = timedate.getTime() - now.getTime(); var time = Math.floor(date / (1000 * 60 * 60 * 24)); if (time >= 0) document.write("現(xiàn)在離"+times+"還有: "+time +"天") </Script> 單擊按鈕打印出當(dāng)前頁 <Script Language="JavaScript"> if (window.print) { document.write('<form>' + '<input type=button name=print value="打印本頁" ' + 'onClick="javascript:window.print()"></form>'); } </Script> 單擊按鈕‘另存為’當(dāng)前頁 <input type="button" name="Button" value="保存本頁" onClick="document.all.button.ExecWB(4,1)"> <object id="button" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> <embed width="0" height="0"></embed> </object> 顯示系統(tǒng)當(dāng)前日期 <script language=JavaScript> today=new Date(); function date(){ this.length=date.arguments.length for(var i=0;i<this.length;i++) this[i+1]=date.arguments } var d=new date("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); document.write( "<font color=##000000 style='font-size:9pt;font-family: 宋?> ", today.getYear(),"年",today.getMonth()+1,"月",today.getDate(),"日", d[today.getDay()+1],"</font>" ); </script> 不同時間段顯示不同問候語 <Script Language="JavaScript"> var text=""; day = new Date( ); time = day.getHours( ); if (( time>=0) && (time < 7 )) text="夜貓子,要注意身體哦! " if (( time >= 7 ) && (time < 12)) text="今天的陽光真燦爛啊,你那個朋友呢?" if (( time >= 12) && (time < 14)) text="午休時間。您要保持睡眠哦!" if (( time >=14) && (time < 18)) text="祝您下午工作愉快! " if ((time >= 18) && (time <= 22)) text="您又來了,可別和MM聊太久哦!" if ((time >= 22) && (time < 24)) text="您應(yīng)該休息了!" document.write(text) </Script> 水中倒影效果 <img id="reflect" src="你自己的圖片文件名" width="175" height="59"> <script language="JavaScript"> function f1() { setInterval("mdiv.filters.wave.phase+=10",100); } if (document.all) { document.write('<img id=mdiv src="'+document.all.reflect.src+'" style="filter:wave(strength=3,freq=3,phase=0,lightstrength=30) blur() flipv()">') window.onload=f1 } </script> 慢慢變大的窗口 <Script Language="JavaScript"> <!-- var Windowsheight=100 var Windowswidth=100 var numx=5 function openwindow(thelocation){ temploc=thelocation&, amp;, nbsp; if (!(window.resizeTo&&document.all)&&!(window.resizeTo&&document.getElementById)) { window.open(thelocation) return } windowsize=window.open("","","scrollbars") windowsize.moveTo(0,0) windowsize.resizeTo(100,100) tenumxt() } function tenumxt(){ if (Windowsheight>=screen.availHeight-3) numx=0 windowsize.resizeBy(5,numx) Windowsheight+=5 Windowswidth+=5 if (Windowswidth>=screen.width-5) { windowsize.location=temploc Windowsheight=100 Windowswidth=100 numx=5 return } setTimeout("tenumxt()",50) } //--> </script> <a href="javascript:openwindow('http://www.31u.net')">進(jìn)入</a> 鼠標(biāo)指向時彈出信息框 在<body></body>之間加上如下代碼: <a href onmouseover="alert('彈出信息!')">顯示的鏈接文字</a> 隨機(jī)變換背景圖象(一個可以刷新心情的特效) 在<head></head>之間加上如下代碼: <Script Language="JavaScript"> image = new Array(4); //定義image為圖片數(shù)量的數(shù)組 image [0] = 'tu0.gif' //背景圖象的路徑 image [1] = 'tu1.gif' image [2] = 'tu2.gif' image [3] = 'tu3.gif' image [4] = 'tu4.gif' number = Math.floor(Math.random() * image.length); document.write("<BODY background="/+image[number]+">"); </Script> 鼠標(biāo)一碰就給顏色看的鏈接 在<body></body>之間加上如下代碼: <p onMouseMove="anniu()">你敢碰我,我就給點(diǎn)顏色你看!</p> <Script Language = "VBScript"> sub anniu document.fgColor=int(256*256*256*rnd) end sub </Script> 從天而降并有幻影效果的窗口 <head> <Script language="JavaScript"> function move(x) { if(self.moveBy){ self.moveBy (0,-800); for(i = x; i > 0; i--) { self.moveBy(0,3); } for(j = 200; j > 0; j--){ //如果你認(rèn)為窗口抖動厲害,就200換成個位數(shù) self.moveBy(0,j); self.moveBy(j,0); self.moveBy(0,-j); self.moveBy(-j,0); } } } </Scrip> <body bgColor=#ffffff onload=move(280)> </body> </head> 表格的半透明顯示效果 在<head></head>之間加上如下代碼: <style> .alpha{filter: Alpha(Opacity=50)} //50表示50%的透明度 </style> 在<body></body>之間加上如下代碼: <table border="1" width="100" height="62" class="alpha" bgcolor="#F2A664" > <tr> <td width="100%" height="62"> <div align="center">很酷吧!</div> </td> </tr> </table> 鎖定狀態(tài)欄文字防止顯示地址 <body onmouseover="self.status='文字';return true"> 禁止圖片下載 在<body......>這里的最后加入: oncontextmenu="return false" ondragstart="return false" onselectstart="return false" scroll="auto" 禁止緩存 <meta http-equiv="Expires" CONTENT="0"> <meta http-equiv="Cache-Control" CONTENT="no-cache"> <meta http-equiv="Pragma" CONTENT="no-cache"> 加在HEAD里 使用包含頁面 加密所包含頁面地址,使用工具 htmlguardian5.3.5 目前功能最強(qiáng)的html代碼加密軟件,可以保護(hù)連接和html代碼被盜。1.鎖右鍵。2.禁鼠標(biāo)圈選。3.不允許離線使用。4.密碼保護(hù)。5.不顯示狀態(tài)欄url地址。6.全代碼 或 局部代碼保護(hù)。7.鏈接跟蹤。8.禁止打印(IE5+)。9.壓縮代碼( 未加密前)。10.可加密*.html *.js *.asp *.vbs。11.兩種不同加密算法。12.加密 frameset 結(jié)構(gòu)。13.某些功能支持幾個不同版本的瀏覽器。 下載flash我的三種方法: --查看源文件,找出flash的絕對路徑,復(fù)制,在flashget(或螞蟻)中點(diǎn)任務(wù) ,然后點(diǎn)新建下載任務(wù)即可。 --在IE的臨時文件夾Temporary Internet Files里把所有的東西都刪掉,然后 刷新你想要下載flash的網(wǎng)頁,即可得到你所要的flash --使用外部軟件,推薦使用Flash Catcher,安裝后只需在你所要下載的flash上右鍵,save即可。 讓IFRAME框架內(nèi)的文檔的背景透明 <iframe src="about:<body style='background:transparent'>" allowtransparency></iframe> 進(jìn)入頁面后立即自動刷新? <meta http-equiv="refresh" content="120;url=http://www.31u.net"> 打開窗口即最大化 <script language="JavaScript"> <!-- Begin self.moveTo(0,0) self.resizeTo(screen.availWidth,screen.availHeight) // End --> </script> 能隱藏IFRAME的滾動條嗎?我知道的三種方法: 1. 設(shè)置iframe scrolling="no" 2. 被包含頁body應(yīng)用overflow:hidden 3. 被包含頁的body標(biāo)簽加scroll="no" 加入背景音樂 <bgsound src="mid/windblue[1].mid" loop="-1"> 只適用于IE <embed src="music.mid" autostart="true" loop="true" hidden="true"> 對Netscape ,IE 都適用 嵌入網(wǎng)頁 <iframe name="tt" src="/01a.html" width="450" height="287" scrolling="Auto" frameborder="0"></iframe> 跳轉(zhuǎn) <meta http-equiv="refresh" content="3;URL=list.htm"> 滾動 <MARQUEE direction=up height=146 onmouseout=start() onmouseover=stop() scrollAmount=4> </marquee> 細(xì)線分隔線 <hr noshade size=0 color=#C0C0C0> 過度方式 <meta http-equiv="Page-Exit" content="revealTrans(Duration=3,Transition=5)"> Duration的值為網(wǎng)頁動態(tài)過渡的時間,單位為秒。 Transition是過渡方式,它的值為0到23,分別對應(yīng)24種過渡方式。如下表: 0 盒狀收縮 1 盒狀放射 2 圓形收縮 3 圓形放射 4 由下往上 5 由上往下 6 從左至右 7 從右至左 8 垂直百葉窗 9 水平百葉窗 10 水平格狀百葉窗 11垂直格狀百葉窗 12 隨意溶解 13從左右兩端向中間展開 14從中間向左右兩端展開 15從上下兩端向中間展開 16從中間向上下兩端展開 17 從右上角向左下角展開 18 從右下角向左上角展開 19 從左上角向右下角展開 20 從左下角向右上角展開 21 水平線狀展開 22 垂直線狀展開 23 隨機(jī)產(chǎn)生一種過渡方式 如何控制橫向和縱向滾動條的顯隱? <body style="overflow-y:hidden"> 去掉x軸 <body style="overflow-x:hidden"> 去掉y軸 <body scroll="no">不顯 定義本網(wǎng)頁關(guān)鍵字,可以在<Head></Head>中加入如下代碼: <meta name="Keywords" content="china,enterprise,business,net"> Content 中所包含的就是關(guān)鍵字,你可以自行設(shè)置。 這里有個技巧,你可以重復(fù)某一個單詞,這樣可以提高自己網(wǎng)站的排行位置,如: <meta name="Keywords" content="china,china,china,china"> IE5.0 的部分快捷鍵: A:打開查找功能:Ctrl+F 關(guān)閉瀏覽器窗口:Ctrl+W 打開地址欄下拉列表框:F4 刷 新:F5 將當(dāng)前Web頁保存到收藏夾列表:Ctrl+D 打開當(dāng)前 IE 窗口的一個拷貝:Ctrl+N 停止下載當(dāng)前網(wǎng)頁:Esc 光標(biāo)迅速移動到網(wǎng)頁的開頭:Home 光標(biāo)迅速移動到網(wǎng)頁的尾部:End 打開新的地址鍵入窗口:Ctrl+O 打開收藏夾:Ctrl+I 打開歷史記錄文件夾:Ctrl+H 打開瀏覽器設(shè)定的默認(rèn)主頁:Alt+HOME 添加到收藏夾: <a href="javascript:window.external.addFavorite('http://鏈接','說明');">添加到收藏夾</a> 設(shè)為首頁: <a href=# onclick=this.style.behavior='url(#default#homepage)';this.setHomePage ('http://鏈接');>設(shè)為首頁</a> 定制瀏覽器地址欄前的小圖標(biāo): A:在網(wǎng)頁的<head></head>間加入以下語句 <link rel="shortcuticon" href="http://…/icon.ico"> 即可。其中 icon.ico 為 16x16 的圖標(biāo)文件, 顏色不要超過 16 色。 把滾動條放在瀏覽器窗口的左邊 A:在 <body> 中加 dir=RTL,即 <body dir=RTL>。 讓背景圖不滾動 IE瀏覽器支持一個 Body 屬性 bgproperties,它可以讓背景不滾動: <Body Background="圖片文件" bgproperties="fixed"> 刪除確認(rèn): <input type="button" name="DEL" onclick="{if(confirm('確認(rèn)刪除么?')){location.href="/xxx.asp";}return false;}" value="ON" > 隱藏狀態(tài)欄中的鏈接地址: <script language="javascript"> kstatus(); function kstatus(){ self.status="GBlog () "; setTimeout("kstatus()",0); } </script> 自定義指定區(qū)域的文字大小: <div id=zoom>sdrrrrrrrrrrrrrrrrrrrrrrrrrrrrr</div> 【<A href="javascript:doZoom(16)">大</A> <A href="javascript:doZoom(14)">中</A> <A href="javascript:doZoom(12)">小</A>】 <SCRIPT language=JavaScript> function doZoom(size){ document.getElementById('zoom').style.fontSize=size+'px' } </script> Input輸入框文字效果: <input type="text" value="123456" style="FONT-size:38px;color:red;font-family:arial black"> 通過層來實(shí)現(xiàn)漸淡淡出 <script language="JavaScript1.2"> function makevisible(cur,which){ if (which==0) cur.filters.alpha.opacity=100 else cur.filters.alpha.opacity=50 } </script> <div style="width:200px;height:200px;filter:alpha(opacity=50);border:1px solid #000;background:#efefef" onMouseOver="makevisible(this,0)" onMouseOut="makevisible(this,1)"> ywicc.com </div> 網(wǎng)頁屏保 <script language="JavaScript"> function screensave(){ test.value++; if(test.value==5){ test.style.display='none'; document.all[4].bgColor='black'; } } function screenopen(){ test.value=0; test.style.display=''; document.all[4].bgColor=''; } </script> <body onkeydown="screenopen()" onmousemove="screenopen()" onload="setInterval('screensave()',1000)"> 5 秒屏保<input id="test"> 讓標(biāo)題動態(tài) <script> <!-- var tx = new Array ( "◇:::::::網(wǎng)頁制作學(xué)習(xí)園地:::::::◇歡迎您!◇", "◆歡迎大家光臨網(wǎng)頁制作學(xué)習(xí)園地網(wǎng)站!◆", "◆大量供應(yīng)網(wǎng)頁制作教材,資料,源代碼,網(wǎng)頁制作軟件,相關(guān)插件光盤!◆", "◆最可怕的敵人,就是沒有堅(jiān)強(qiáng)的信念!◆", "◆應(yīng)該讓別人的生活因?yàn)橛辛四愕纳娑用篮?◆" ); var txcount=5; var i=1; var wo=0; var ud=1; function animatetitle() { window.document.title=tx[wo].substr(0, i)+"_"; if (ud==0) i--; if (ud==1) i++; if (i==-1) {ud=1;i=0;wo++;wo=wo%txcount;} if (i==tx[wo].length+10) {ud=0;i=tx[wo].length;} // if (window.document.title.length < 20 ) window.document.title=window.document.title+"-"; // if (window.document.title.length == 20 ) window.document.title=window.document.title+"]"; // if (window.document.title.length == 21 ) setTimeout("window.document.title='Animierte Seitentitel '; ",1000); parent.window.document.title=tx[wo].substr(0, i)+"_"; setTimeout("animatetitle()",100); } animatetitle(); // --></script><script language="JavaScript"> <!-- function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script> 隱去瀏覽器中當(dāng)鼠標(biāo)移到圖片上跳出的工具欄 <img galleryimg="no"> 或者 <head> <meta http-equiv="imagetoolbar" content="no"> </head> 在form中只有input輸入框的情況下...在這個input輸入框中按enter進(jìn)行提交表單 <form onsubmit="if(event.srcElement.name=='bb'){this.submit()}else{return false}"> <input name=a size=20> <input type=button name=bb onclick="submit();"> </form> 刪除確認(rèn) <input type="button" value="刪除" onclick="{if(confirm('確認(rèn)刪除么?')){location.href="/aa.asp";}return false;}"> 或 <a href="http://www.31u.net/search.asp" onclick="{if(confirm('確定刪除嗎?')){return true;}return false;}">刪除</a> 或 <a href="http://www.31u.net/search.asp" onclick="return confirm('該刪除操作將無法恢復(fù)!是否繼續(xù)?')">刪除</a> 返回頁面頂部: javascript:window.scroll(0,0) 離開頁面時彈出警告: <BODY onbeforeunload="checkclose()"> <SCRIPT> function checkclose(){ event.returnValue = "測試啊" //XXX可以改為任何文本信息也可以是空 } </SCRIPT> <a >aa</a> | ||
| ||
posted on 2006-03-13 14:50 都市淘沙者 閱讀(366) 評論(0) 編輯 收藏 所屬分類: JSP/PHP