asp

位置:IT落伍者 >> asp >> 浏览文章

一些初学都常用的ASP代码


发布日期:2021年09月06日
 
一些初学都常用的ASP代码

获得系统时间:

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

               

上一篇:Asp组件初级入门与精通系列之一

下一篇:深入讲解 ASP+ 验证(一)