熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

一些初學都常用的ASP代碼

2013-11-13 10:03:43  來源: .NET編程 

  獲得系統時間:

<%=now()%>

取得來訪用的IP:

<%=requestserverVariables(\remote_host\)%>

    獲得系統浏覽器版本:

<script>
windowdocumentwrite(\版本\+navigatorappName+navigatorappVersion+\ browser\)
</script>
   去除IE混動條:

<body scroll=\no\>
<body style=\overflowy:hidden\>

    進入網站跳出廣告:

<script language=\javascript\>
<!
<! 注意更改文件所在路徑>
windowopen(\\\\\height=width=top=left=\);
// >
</script>

    隨機數:

<%randomize%>
<%=(int(rnd()*n)+)%>
N為可改變數
  向上混動代碼:

<marquee direction=\up\ scrolldelay=\\ style=\fontsize: pt; color: #FF; lineheight: %; fontstyle:italic; fontweight:bold\ scrollamount=\\ width=\\ height=\\ bgcolor=\#FFFF\>hhhhhhhhhhhhhhhhhhh</marquee>

    自動關閉網頁:

<script LANGUAGE=\javascript\>
<!
setTimeout(\windowclose();\ ); //秒後關閉
// >
</script>
<p align=\center\>本頁秒後自動關閉請注意刷新頁面</p>

   隨機背景音樂:

<%randomize%>
<bgsound src=\mids/<%=(int(rnd()*)+)%>mid\ loop=\\>
可以修改數字限制調用個數我這裡是60個.

    自動刷新本頁面:

<script>
<!

  var limit=\:\

  if (documentimages){
var parselimit=limitsplit(\:\)
parselimit=parselimit[]*+parselimit[]*
}
function beginrefresh(){
if (!documentimages)
return
if (parselimit==)
windowlocationreload()
else{
parselimit=
curmin=Mathfloor(parselimit/)
cursec=parselimit%
if (curmin!=)
curtime=curmin+\分\+cursec+\秒後重刷本頁!\
else
curtime=cursec+\秒後重刷本頁!\
windowstatus=curtime
setTimeout(\beginrefresh()\)
}
}

  windowonload=beginrefresh
file://>
</script>

  ACCESS數據庫連接:

<%
option explicit
dim startimeendtimeconnconnstrdb
startime=timer()
\更改數據庫名字
db=\data/dvBBSmdb\
Set conn = ServerCreateObject(\ADODBConnection\)
connstr=\Provider=MicrosoftJetOLEDB;Data Source=\ & ServerMapPath(db)
\如果你的服務器采用較老版本Access驅動請用下面連接方法
\connstr=\driver={Microsoft Access Driver (*mdb)};dbq=\ & ServerMapPath(db)
connOpen connstr
function CloseDatabase
Connclose
Set conn = Nothing
End Function
%>

   SQL數據庫連接:

<%
option explicit
dim startimeendtimeconnconnstrdb
startime=timer()
connstr=\driver={SQL Server};server=HUDENQNTNB;uid=sa;pwd=xsfeihu;database=dvbbs\
Set conn = ServerCreateObject(\ADODBConnection\)
connOpen connstr
function CloseDatabase
Connclose
Set conn = Nothing
End Function
%>

  用鍵盤打開網頁代碼:

<script language=\javascript\>
function ctlent(eventobject)
{
if((eventctrlKey && windoweventkeyCode==)||(eventaltKey && windoweventkeyCode==))
{
windowopen(\網址\\\\\)
}
}
</script>

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

   讓層不被控件復蓋代碼:

<div zIndex:><object xxx></object></div> # 前面
<div zIndex:><object xxx></object></div> # 後面
<div id=\Layer\ style=\position:absolute; top:;width:px; height:px;zindex:\><table height=% width=% bgcolor=\#ff\><tr><td height=% width=%></td></tr></table><iframe width= height=></iframe></div>
<div id=\Layer\ style=\position:absolute; top:;width:px; height:px;zindex:\><iframe height=% width=%></iframe></div>

    動網FLASH廣告代碼:

<object classid=\clsid:DCDBEAEDcfB\ codebase=\#version=\ width=\\ height=\\><param name=movie value=\images/yjdswf\><param name=quality value=high><embed src=\//swf\ quality=high pluginspage=\_Prod_Version=ShockwaveFlash\;;;;;;;;;;;; type=\application/xshockwaveflash\ width=\\ height=\\></embed></object>

    VBS彈出窗口小代碼:

<script language=vbscript>
msgbox\你還沒有注冊或登陸論壇\\\\精品論壇



\
locationhref = \loginasp\
</script>

   使用FSO修改文件特定內容的函數

function FSOchange(filenameTargetString)
Dim objFSOobjCountFileFiletempData
Set objFSO = ServerCreateObject(\ScriptingFileSystemObject\)
Set objCountFile = objFSOOpenTextFile(ServerMapPath(filename)True)
FiletempData = objCountFileReadAll
objCountFileClose
FiletempData=Replace(FiletempDataTargetString)
Set objCountFile=objFSOCreateTextFile(ServerMapPath(filename)True)
objCountFileWrite FiletempData
objCountFileClose
Set objCountFile=Nothing
Set objFSO = Nothing
End Function

   使用FSO讀取文件內容的函數

function FSOFileRead(filename)
Dim objFSOobjCountFileFiletempData
Set objFSO = ServerCreateObject(\ScriptingFileSystemObject\)
Set objCountFile = objFSOOpenTextFile(ServerMapPath(filename)True)
FSOFileRead = objCountFileReadAll
objCountFileClose
Set objCountFile=Nothing
Set objFSO = Nothing
End Function

    使用FSO讀取文件某一行的函數

function FSOlinedit(filenamelineNum)
if linenum < then exit function
dim fsoftemparraytempcnt
set fso = serverCreateObject(\scriptingfilesystemobject\)
if not fsofileExists(servermappath(filename)) then exit function
set f = fsoopentextfile(servermappath(filename))
if not fAtEndofStream then
tempcnt = freadall
fclose
set f = nothing
temparray = split(tempcntchr()&chr())
if lineNum>ubound(temparray)+ then
exit function
else
FSOlinedit = temparray(lineNum)
end if
end if
end function

  使用FSO寫文件某一行的函數

function FSOlinewrite(filenamelineNumLinecontent)
if linenum < then exit function
dim fsoftemparraytempCnt
set fso = serverCreateObject(\scriptingfilesystemobject\)
if not fsofileExists(servermappath(filename)) then exit function
set f = fsoopentextfile(servermappath(filename))
if not fAtEndofStream then
tempcnt = freadall
fclose
temparray = split(tempcntchr()&chr())
if lineNum>ubound(temparray)+ then
exit function
else
temparray(lineNum) = lineContent
end if
tempcnt = join(temparraychr()&chr())
set f = fsocreatetextfile(servermappath(filename)true)
fwrite tempcnt
end if
fclose
set f = nothing
end function

    使用FSO添加文件新行的函數

function FSOappline(filenameLinecontent)
dim fsof
set fso = serverCreateObject(\scriptingfilesystemobject\)
if not fsofileExists(servermappath(filename)) then exit function
set f = fsoopentextfile(servermappath(filename))
fwrite chr()&chr()&Linecontent
fclose
set f = nothing
end function

    讀文件最後一行的函數

function FSOlastline(filename)
dim fsoftemparraytempcnt
set fso = serverCreateObject(\scriptingfilesystemobject\)
if not fsofileExists(servermappath(filename)) then exit function
set f = fsoopentextfile(servermappath(filename))
if not fAtEndofStream then
tempcnt = freadall
fclose
set f = nothing
temparray = split(tempcntchr()&chr())
FSOlastline = temparray(ubound(temparray))
end if
end function


From:http://tw.wingwit.com/Article/program/net/201311/12439.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.