asp/js函數收藏/代碼/JScript[40條]/JS寶典

[ Copy ] [ Run ] [ Save ]

'*******************************************************************
'檢測是否是手機瀏覽
'*******************************************************************
<%
if instr(request.ServerVariables("HTTP_USER_AGENT"),"Mozilla")=0 then
response.redirect "/wap" '如果客戶端爲手機訪問,則進入/wap目錄
else
response.redirect "[url]http://wap.fz0132.com[/url]" '如果客戶端不是手機訪問,則進入指定地址
end if
%>




[ Copy ] [ Run ] [ Save ]
'*******************************************************************
'取得IP地址
'*******************************************************************
Function Userip()
  Dim GetClientIP
  '如果客戶端用了代理服務器,則應該用ServerVariables("HTTP_X_FORWARDED_FOR")方法
  GetClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
  If GetClientIP = "" or isnull(GetClientIP) or isempty(GetClientIP) Then
    '如果客戶端沒用代理,應該用Request.ServerVariables("REMOTE_ADDR")方法
    GetClientIP = Request.ServerVariables("REMOTE_ADDR")
  end if
  Userip = GetClientIP
End function





[ Copy ] [ Run ] [ Save ]
'*******************************************************************
' 彈出對話框
'*******************************************************************
Sub alert(message)
message = replace(message,"'","/'")
Response.Write ("<script>alert('" & message & "')</script>")
End Sub
 



[ Copy ] [ Run ] [ Save ]
'*******************************************************************
' 返回上一頁,一般用在判斷信息提交是否完全之後
'*******************************************************************
Sub GoBack()
Response.write ("<script>history.go(-1)</script>")
End Sub
 



[ Copy ] [ Run ] [ Save ]
'*******************************************************************
' 重定向另外的連接
'*******************************************************************
Sub Go(url)
Response.write ("<script>location.href('" & url & "')</script>")
End Sub

 


[ Copy ] [ Run ] [ Save ]
'*******************************************************************
' 指定秒數重定向另外的連接
'*******************************************************************
sub GoPage(url,s)
s=s*1000
Response.Write "<SCRIPT LANGUAGE=JavaScript>"
Response.Write "window.setTimeout("&chr(34)&"window.navigate('"&url&"')"&chr(34)&","&s&")"
Response.Write "</script>"
end sub




[ Copy ] [ Run ] [ Save ]
'*******************************************************************
' 判斷數字是否整形
'*******************************************************************
function isInteger(para)
on error resume next
dim str
dim l,i
if isNUll(para) then
isInteger=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isInteger=false
exit function
end if
l=len(str)
for i=1 to l
if mid(str,i,1)>"9" or mid(str,i,1)<"0" then
isInteger=false
exit function
end if
next
isInteger=true
if err.number<>0 then err.clear
end function

 


[ Copy ] [ Run ] [ Save ]
'*******************************************************************
' 獲得文件擴展名
'*******************************************************************
function GetExtend(filename)
dim tmp
if filename<>"" then
tmp=mid(filename,instrrev(filename,".")+1,len(filename)-instrrev(filename,"."))
tmp=LCase(tmp)
if instr(1,tmp,"asp")>0 or instr(1,tmp,"php")>0 or instr(1,tmp,"php3")>0 or instr(1,tmp,"aspx")>0 then
getextend="txt"
else
getextend=tmp
end if
else
getextend=""
end if
end function

 


[ Copy ] [ Run ] [ Save ]
' *----------------------------------------------------------------------------
' * 函數:CheckIn
' * 描述:檢測參數是否有SQL危險字符
' * 參數:str要檢測的數據
' * 返回:FALSE:安全 TRUE:不安全
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function CheckIn(str)
if instr(1,str,chr(39))>0 or instr(1,str,chr(34))>0 or instr(1,str,chr(59))>0 then
CheckIn=true
else
CheckIn=false
end if
end function




[ Copy ] [ Run ] [ Save ]
' *----------------------------------------------------------------------------
' * 函數:HTMLEncode
' * 描述:過濾HTML代碼
' * 參數:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLEncode(fString)
if not isnull(fString) then
fString = replace(fString, ">", ">")
fString = replace(fString, "<", "<")

fString = Replace(fString, CHR(32), " ")
fString = Replace(fString, CHR(9), " ")
fString = Replace(fString, CHR(34), """)
fString = Replace(fString, CHR(39), "'")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")

HTMLEncode = fString
end if
end function




[ Copy ] [ Run ] [ Save ]
'*----------------------------------------------------------------------------
' * 函數:HTMLcode
' * 描述:過濾表單字符
' * 參數:--
' * 返回:--
' * 作者:
' * 日期:
' *----------------------------------------------------------------------------
function HTMLcode(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(34), "")
fString = Replace(fString, CHR(10), "<BR>")
HTMLcode = fString
end if
end function



so cool 菜單(Jave)


[ Copy ] [ Run ] [ Save ]
<style>
body{
  background-color:#B8B8A0;
  }
#fbtn{
  display:none;
  overflow:hidden;
  border-style:solid;
  border-width:1px;
  border-color:#e1e1c9 #e1e1c9 #6e6e56 #6e6e56;
  padding:1 1 1 1;
  width:115px;
  height:30px;
  }
#fbtn_txt{
  position:relative;
  }
#fbtn_txt div{
  height:30px;
  padding-top:11px;
  font-size:9px;
  font-family:small fonts;
  color:#800080;
  text-align:center;
  cursor:hand;
  }
#fbtn_mask{
  background-color:#ffffff;
  position:relative;
  width:100%;
  height:100%;
  }
</style>

<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>G1</div>
    <div>good morning</div>
  </div>
</div>
<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>G2</div>
    <div>good evening</div>
  </div>
</div>
<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>M1</div>
    <div>my name is mozart0</div>
  </div>
</div>
<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>M2</div>
    <div>mm mm i love u</div>
  </div>
</div>
<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>G1</div>
    <div>good morning</div>
  </div>
</div>
<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>G2</div>
    <div>good evening</div>
  </div>
</div>
<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>M1</div>
    <div>my name is mozart0</div>
  </div>
</div>
<div id=fbtn>
  <div id=fbtn_mask></div>
  <div id=fbtn_txt>
    <div>M2</div>
    <div>mm mm i love u</div>
  </div>
</div>

<script>
var current=null;
for(var i=0;i<fbtn.length;i++){
  fbtn_txt[i].style.posTop=-30;
  fbtn_mask[i].style.posTop=-30;
  fbtn[i].index=i;
  fbtn[i].style.display="block";
  fbtn[i].onmouseover=function(){
    if(!current){
        current=this;
        domove(this.index);
        }
    else if(current!=this){
        domove(current.index);
        domove(this.index);
        current=this;
        }
    }
  fbtn[i].onmouseout=function(){
    if(event.toElement==this.parentElement&¤t==this){
        domove(this.index);
        current=null;
        }
    }
  }
function domove(num){
  var o=fbtn_txt[num];
  var m=fbtn_mask[num];
  if(o.style.posTop<-60){
    o.style.display="none";
    var t=o.children[1].innerHTML;
    o.children[1].innerHTML=o.children[0].innerHTML;
    o.children[0].innerHTML=t;
    o.style.posTop=-30;
    o.style.display="block";
    if(m.style.posTop>30)
        m.style.posTop=-30;
    else
        m.style.posTop=0;
    }
  else{
    m.style.posTop+=3;
    o.style.posTop-=3;
    setTimeout('domove('+num+')',15);
    }
  }
</script>
《幾個常用的ASP代碼&FSO》
1.獲得系統時間:
<%=now()%>

2.取得來訪用的IP:
<%=request.serverVariables("remote_host")%>

3.獲得系統,瀏覽器版本:
<script>
window.document.write("版本:"+navigator.appName+navigator.appVersion+" browser.")
</script>

4.去除IE混動條:
<body scroll="no">
<body style="overflow-y:hidden">

5.進入網站,跳出廣告:
<script language="javascript">
<!--
<!-- 注意更改文件所在路徑-->
window.open('[url]http://www.XXXXXX.com'[/url],'','height=200,width=300,top=0,left=30');
// -->
</script>

6.隨機數:
<%randomize%>
<%=(int(rnd()*n)+1)%>
N爲可改變數

7.向上混動代碼:
<marquee direction="up" scrolldelay="200" style="font-size: 9pt; color: #FF0000; line-height: 150%; font-style:italic; font-weight:bold" scrollamount="2" width="206" height="207" bgcolor="#FFFF00">hhhhhhhhhhhhhhhhhhh</marquee>

8.自動關閉網頁:
<script LANGUAGE="javascript">
<!--
setTimeout('window.close();', 10000); //60秒後關閉
// -->
</script>
<p align="center">本頁10秒後自動關閉,請注意刷新頁面</p>

9.隨機背景音樂:
<%randomize%>
<bgsound src="mids/<%=(int(rnd()*60)+1)%>.mid" loop="-1">
可以修改數字,限制調用個數,我這裏是60個.

10.自動刷新本頁面:
<script>
<!--

var limit="0:10"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+"分"+cursec+"秒後重刷本頁!"
else
curtime=cursec+"秒後重刷本頁!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
file://-->
</script>

11.ACCESS數據庫連接:
<%
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
'更改數據庫名字
db="data/dvBBS5.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
'如果你的服務器採用較老版本Access驅動,請用下面連接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
conn.Open connstr
function CloseDatabase
Conn.close
Set conn = Nothing
End Function
%>

12.SQL數據庫連接:
<%
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
connstr="driver={SQL Server};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
function CloseDatabase
Conn.close
Set conn = Nothing
End Function
%>

13.用鍵盤打開網頁代碼:
<script language="javascript">
function ctlent(eventobject)
{
if((event.ctrlKey && window.event.keyCode==13)||(event.altKey && window.event.keyCode==83))
{
window.open('網址','','')
}
}
</script>

這裏是Ctrl+Enter和Alt+S的代碼 自己查下鍵盤的ASCII碼再換就行

14.讓層不被控件覆蓋代碼:
<div z-Index:2><object xxx></object></div> # 前面
<div z-Index:1><object xxx></object></div> # 後面
<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>
<div id="Layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>

15.動網FLASH廣告代碼:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="[url]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5[/url],0,0,0" width="468" height="60"><param name=movie value="/images/yj16d.swf"><param name=quality value=high><embed src="/images/dvbanner.swf" quality=high pluginspage="[url]http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash[/url]";;;;;;;;;;;; type="application/x-shockwave-flash" width="468" height="60"></embed></object>

16.VBS彈出窗口小代碼:
<script language=vbscript>
msgbox"你還沒有註冊或登陸論壇","0","精品論壇"
location.href = "login.asp"
</script>

16.使用FSO修改文件特定內容的函數
function FSOchange(filename,Target,String)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FiletempData = objCountFile.ReadAll
objCountFile.Close
FiletempData=Replace(FiletempData,Target,String)
Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
objCountFile.Write FiletempData
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function

17.使用FSO讀取文件內容的函數
function FSOFileRead(filename)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FSOFileRead = objCountFile.ReadAll
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function

18.使用FSO讀取文件某一行的函數
function FSOlinedit(filename,lineNum)
if linenum < 1 then exit function
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
FSOlinedit = temparray(lineNum-1)
end if
end if
end function

19.使用FSO寫文件某一行的函數
function FSOlinewrite(filename,lineNum,Linecontent)
if linenum < 1 then exit function
dim fso,f,temparray,tempCnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
temparray(lineNum-1) = lineContent
end if
tempcnt = join(temparray,chr(13)&chr(10))
set f = fso.createtextfile(server.mappath(filename),true)
f.write tempcnt
end if
f.close
set f = nothing
end function

20.使用FSO添加文件新行的函數
function FSOappline(filename,Linecontent)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),8,1)
f.write chr(13)&chr(10)&Linecontent
f.close
set f = nothing
end function

21.讀文件最後一行的函數
function FSOlastline(filename)
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
FSOlastline = temparray(ubound(temparray))
end if
end function


1. oncontextmenu="window.event.returnValue=false" 將徹底屏蔽鼠標右鍵
<table border oncontextmenu=return(false)><td>no</table> 可用於Table

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

3. onpaste="return false" 不準粘貼

4. oncopy="return false;" oncut="return false;" 防止複製

5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址欄前換成自己的圖標

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

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

8. 永遠都會帶着框架
<script language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm爲框架網頁
// --></script>

9. 防止被人frame
<SCRIPT LANGUAGE=JAVASCRIPT><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>

10. 網頁將不能被另存爲
<noscript><iframe src="/*.html>";</iframe></noscript>

11. <input type=button value="/查看網頁源代碼
onclick="window.location = "view-source:"+ "[url]http://www.pconline.com.cn[/url]"">

12.刪除時確認
<a href="javascript :if(confirm("確實要刪除嗎?"))location="boos.asp?&areyou=刪除&page=1"">刪除</a>

13. 取得控件的絕對位置
//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>

14. 光標是停在文本框文字的最後
<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()">

15. 判斷上一頁的來源
javascript :
document.referrer

16. 最小化、最大化、關閉窗口
<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=關閉 onclick=hh3.Click()>
本例適用於IE

17.屏蔽功能鍵Shift,Alt,Ctrl
<script>
function look(){
if(event.shiftKey)
alert("禁止按Shift鍵!"); //可以換成ALT CTRL
}
document.onkeydown=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 onblur="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="#" 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 onload="top.resizeTo(300,200);">
打開頁面的位置<body onload="top.moveBy(300,200);">

27.在頁面中如何加入不是滿鋪的背景圖片,拉動頁面時背景圖不動
<STYLE>
body
{background-image:url(/logo.gif); background-repeat:no-repeat;
background-position:center;background-attachment: fixed}
</STYLE>

28. 檢查一段字符串是否全由數字組成
<script language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>

29. 獲得一個窗口的大小
document.body.clientWidth; document.body.clientHeight

30. 怎麼判斷是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有漢字");
else alert("全是字符");

31.TEXTAREA自適應文字行數的多少
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
</textarea>

32. 日期減去天數等於第二個日期
<script language=Javascript>
function cc(dd,dadd)
{
//可以加上錯誤處理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
</script>

33. 選擇了哪一個Radio
<HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="/style" checked>Style
<INPUT name="radio1" type="radio" value="barcode">Barcode
<INPUT type="button" value="check" onclick="checkme()">
</BODY></HTML>

34.腳本永不出錯
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide
function killErrors() {
return true;
}
window.onerror = killErrors;
// -->
</SCRIPT>

35.ENTER鍵可以讓光標移到下一個輸入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9">

36. 檢測某個網站的鏈接速度:
把如下代碼加入<body>區域中:
<script language=Javascript>
tim=1
setInterval("tim++",100)
b=1
var autourl=new Array()
autourl[1]="[url]www.njcatv.net[/url]"
autourl[2]="javacool.3322.net"
autourl[3]="[url]www.sina.com.cn[/url]"
autourl[4]="[url]www.nuaa.edu.cn[/url]"
autourl[5]="[url]www.cctv.com[/url]"
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

onclick=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

onerror=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.51js.com">

40.網頁是否被檢索
<meta name="ROBOTS" content="屬性值">
  其中屬性值有以下一些:
  屬性值爲"all": 文件將被檢索,且頁上鍊接可被查詢;
  屬性值爲"none": 文件不被檢索,而且不查詢頁上的鏈接;
  屬性值爲"index": 文件將被檢索;
  屬性值爲"follow": 查詢頁上的鏈接;
  屬性值爲"noindex": 文件不檢索,但可被查詢鏈接;
  屬性值爲"nofollow": 文件不被檢索,但可查詢頁上的鏈接。

js寶典學習筆記ZT

每一項都是js中的小技巧,但十分的實用!
1.document.write(""); 輸出語句
2.JS中的註釋爲//
3.傳統的HTML文檔順序是:document->html->(head,body)
4.一個瀏覽器窗口中的DOM順序是:window->(navigator,screen,history,location,document)
5.得到表單中元素的名稱和值:document.getElementById("表單中元素的ID號").name(或value)
6.一個小寫轉大寫的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase();
7.JS中的值類型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型轉換成數值型:parseInt(),parseFloat()
9.JS中的數字轉換成字符型:(""+變量)
10.JS中的取字符串長度是:(length)
11.JS中的字符與字符相連接使用+號.
12.JS中的比較操作符有:==等於,!=不等於,>,>=,<.<=
13.JS中聲明變量使用:var來進行聲明
14.JS中的判斷語句結構:if(condition){}else{}
15.JS中的循環結構:for([initial expression];[condition];[upadte expression]) {inside loop}
16.循環中止的命令是:break
17.JS中的函數定義:function functionName([parameter],...){statement[s]}
18.當文件中出現多個form表單時.可以用document.forms[0],document.forms[1]來代替.
19.窗口:打開窗口window.open(), 關閉一個窗口:window.close(), 窗口本身:self
20.狀態欄的設置:window.status="字符";
21.彈出提示信息:window.alert("字符");
22.彈出確認框:window.confirm();
23.彈出輸入提示框:window.prompt();
24.指定當前顯示鏈接的位置:window.location.href="/URL"
25.取出窗體中的所有表單的數量:document.forms.length
26.關閉文檔的輸出流:document.close();
27.字符串追加連接符:+=
28.創建一個文檔元素:document.createElement(),document.createTextNode()
29.得到元素的方法:document.getElementById()
30.設置表單中所有文本型的成員的值爲空:
var form = window.document.forms[0]
for (var i = 0; i<form.elements.length;i++){
  if (form.elements[i].type == "text"){
      form.elements[i].value = "";
  }
}
31.複選按鈕在JS中判斷是否選中:document.forms[0].checkThis.checked (checked屬性代表爲是否選中返回TRUE或FALSE)
32.單選按鈕組(單選按鈕的名稱必須相同):取單選按鈕組的長度document.forms[0].groupName.length
33.單選按鈕組判斷是否被選中也是用checked.
34.下拉列表框的值:document.forms[0].selectName.options[n].value (n有時用下拉列表框名稱加上.selectedIndex來確定被選中的值)
35.字符串的定義:var myString = new String("This is lightsword");
36.字符串轉成大寫:string.toUpperCase(); 字符串轉成小寫:string.toLowerCase();
37.返回字符串2在字符串1中出現的位置:String1.indexOf("String2")!=-1則說明沒找到.
38.取字符串中指定位置的一個字符:StringA.charAt(9);
39.取出字符串中指定起點和終點的子字符串:stringA.substring(2,6);
40.數學函數:Math.PI(返回圓周率),Math.SQRT2(返回開方),Math.max(value1,value2)返回兩個數中的最在值,Math.pow(value1,10)返回value1的十次方,Math.round(value1)四捨五入函數,Math.floor(Math.random()*(n+1))返回隨機數
41.定義日期型變量:var today = new Date();
42.日期函數列表:dateObj.getTime()得到時間,dateObj.getYear()得到年份,dateObj.getFullYear()得到四位的年份,dateObj.getMonth()得到月份,dateObj.getDate()得到日,dateObj.getDay()得到日期幾,dateObj.getHours()得到小時,dateObj.getMinutes()得到分,dateObj.getSeconds()得到秒,dateObj.setTime(value)設置時間,dateObj.setYear(val)設置年,dateObj.setMonth(val)設置月,dateObj.setDate(val)設置日,dateObj.setDay(val)設置星期幾,dateObj.setHours設置小時,dateObj.setMinutes(val)設置分,dateObj.setSeconds(val)設置秒 [注意:此日期時間從0開始計]
43.FRAME的表示方式: [window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent代表父親對象,top代表最頂端對象
45.打開子窗口的父窗口爲:opener
46.表示當前所屬的位置:this
47.當在超鏈接中調用JS函數時用:(javascript :)來開頭後面加函數名
48.在老的瀏覽器中不執行此JS:<!--     //-->
49.引用一個文件式的JS:<script type="text/javascript" src="/aaa.js"></script>
50.指定在不支持腳本的瀏覽器顯示的HTML:<noscript></noscript>
51.當超鏈和ONCLICK事件都有時,則老版本的瀏覽器轉向a.html,否則轉向b.html.例:<a href="/a.html" onclick="location.href="/b.html";return false">dfsadf</a>
52.JS的內建對象有:Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,ReferenceError,RegExp,String,SyntaxError,TypeError,URIError
53.JS中的換行:/n
54.窗口全屏大小:<script>function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;</script>
55.JS中的all代表其下層的全部元素
56.JS中的焦點順序:document.getElementByid("表單元素").tabIndex = 1
57.innerHTML的值是表單元素的值:如<p id="para">"how are <em>you</em>"</p>,則innerHTML的值就是:how are <em>you</em>
58.innerTEXT的值和上面的一樣,只不過不會把<em>這種標記顯示出來.
59.contentEditable可設置元素是否可被修改,isContentEditable返回是否可修改的狀態.
60.isDisabled判斷是否爲禁止狀態.disabled設置禁止狀態
61.length取得長度,返回整型數值
62.addBehavior()是一種JS調用的外部函數文件其擴展名爲.htc
63.window.focus()使當前的窗口在所有窗口之前.
64.blur()指失去焦點.與FOCUS()相反.
65.select()指元素爲選中狀態.
66.防止用戶對文本框中輸入文本:onfocus="this.blur()"
67.取出該元素在頁面中出現的數量:document.all.tags("div(或其它HTML標記符)").length
68.JS中分爲兩種窗體輸出:模態和非模態.window.showModaldialog(),window.showModeless()
69.狀態欄文字的設置:window.status='文字',默認的狀態欄文字設置:window.defaultStatus = '文字.';
70.添加到收藏夾:external.AddFavorite("[url]http://www.dannyg.com[/url]","jaskdlf");
71.JS中遇到腳本錯誤時不做任何操作:window.onerror = doNothing; 指定錯誤句柄的語法爲:window.onerror = handleError;
72.JS中指定當前打開窗口的父窗口:window.opener,支持opener.opener...的多重繼續.
73.JS中的self指的是當前的窗口
74.JS中狀態欄顯示內容:window.status="內容"
75.JS中的top指的是框架集中最頂層的框架
76.JS中關閉當前的窗口:window.close();
77.JS中提出是否確認的框:if(confirm("Are you sure?")){alert("ok");}else{alert("Not Ok");}
78.JS中的窗口重定向:window.navigate("[url]http://www.sina.com.cn[/url]");
79.JS中的打印:window.print()
80.JS中的提示輸入框:window.prompt("message","defaultReply");
81.JS中的窗口滾動條:window.scroll(x,y)
82.JS中的窗口滾動到位置:window.scrollby
83.JS中設置時間間隔:setInterval("expr",msecDelay)或setInterval(funcRef,msecDelay)或setTimeout
84.JS中的模態顯示在IE4+行,在NN中不行:showModalDialog("URL"[,arguments][,features]);
85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue="we really like you and hope you will stay longer.";}} window.onbeforeunload=verifyClose;
86.當窗體第一次調用時使用的文件句柄:onload()
87.當窗體關閉時調用的文件句柄:onunload()
88.window.location的屬性: protocol(http:),hostname([url]www.example.com[/url]),port(80),host([url]www.example.com:80[/url]),pathname("/a/a.html""),hash("#giantGizmo",指跳轉到相應的錨記),href(全部的信息)
89.window.location.reload()刷新當前頁面.
90.window.history.back()返回上一頁,window.history.forward()返回下一頁,window.history.go(返回第幾頁,也可以使用訪問過的URL)
91.document.write()不換行的輸出,document.writeln()換行輸出
92.document.body.noWrap=true;防止鏈接文字折行.
93.變量名.charAt(第幾位),取該變量的第幾位的字符.
94."abc".charCodeAt(第幾個),返回第幾個字符的ASCii碼值.
95.字符串連接:string.concat(string2),或用+=進行連接
96.變量.indexOf("字符",起始位置),返回第一個出現的位置(從0開始計算)
97.string.lastIndexOf(searchString[,startIndex])最後一次出現的位置.
98.string.match(regExpression),判斷字符是否匹配.
99.string.replace(regExpression,replaceString)替換現有字符串.
100.string.split(分隔符)返回一個數組存儲值.
101.string.substr(start[,length])取從第幾位到指定長度的字符串.
102.string.toLowerCase()使字符串全部變爲小寫.
103.string.toUpperCase()使全部字符變爲大寫.
104.parseInt(string[,radix(代表進制)])強制轉換成整型.
105.parseFloat(string[,radix])強制轉換成浮點型.
106.isNaN(變量):測試是否爲數值型.
107.定義常量的關鍵字:const,定義變量的關鍵字:var
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章