【ASP】ASP初学者可方便查询相关的代码

1.获得系统时间:
None.gif<%=now()%>

2.取得来访用的IP:

1None.gif<%=request.serverVariables("remote_host")%>

3.获得系统,浏览器版本:
1None.gif<script>
2None.gifwindow.document.write("版本:"+navigator.appName+navigator.appVersion+" browser.")
3None.gif</script>

4.去除IE混动条:

1None.gif<body scroll="no"> 
2None.gif<body style="overflow-y:hidden">

5.进入网站,跳出广告:

1None.gif<script language="javascript">
2None.gif<!-- 
3None.gif<!-- 注意更改文件所在路径-->
4None.gifwindow.open(''http://www.XXXXXX.com&#39;','''',''height=200,width=300,top=0,left=30'');
5None.gif// -->
6None.gif</script>
7None.gif

6.随机数:
1None.gif<%randomize%>
2None.gif<%=(int(rnd()*n)+1)%>

N为可改变数

7.向上混动代码:

1None.gif<marquee direction="up" scrolldelay="200" style="font-size: 9pt; color: #FF0000;
2None.gifline-height: 150%; font-style:italic; font-weight:bold" scrollamount="2" width="206"
3None.gifheight="207" bgcolor="#FFFF00">hhhhhhhhhhhhhhhhhhh</marquee>
4None.gif

8.自动关闭网页:

1None.gif<script LANGUAGE="javascript">
2None.gif<!--
3None.gifsetTimeout(''window.close();'', 10000); //60秒后关闭
4None.gif// -->
5None.gif</script>
6None.gif<align="center">本页10秒后自动关闭,请注意刷新页面</p>
7None.gif

9.随机背景音乐:

1None.gif<%randomize%>
2None.gif<bgsound src="mids/<%=(int(rnd()*60)+1)%>.mid" loop="-1"> 
3None.gif

可以修改数字,限制调用个数,我这里是60个.

10.自动刷新本页面:

 1None.gif<script> 
 2None.gif<!--  
 3None.gif 
 4None.gifvar limit="0:10"  
 5None.gif 
 6None.gifif (document.images){ 
 7None.gifvar parselimit=limit.split(":"
 8None.gifparselimit=parselimit[0]*60+parselimit[1]*1 
 9None.gif } 
10None.giffunction beginrefresh(){ 
11None.gifif (!document.images) 
12None.gifreturn 
13None.gifif (parselimit==1
14None.gifwindow.location.reload() 
15None.gifelse
16None.gifparselimit-=1 
17None.gifcurmin=Math.floor(parselimit/60
18None.gifcursec=parselimit%60 
19None.gifif (curmin!=0
20None.gifcurtime=curmin+""+cursec+"秒后重刷本页!" 
21None.gifelse 
22None.gifcurtime=cursec+"秒后重刷本页!" 
23None.gifwindow.status=curtime 
24None.gifsetTimeout("beginrefresh()",1000
25None.gif
26None.gif}  
27None.gif
28None.gifwindow.onload=beginrefresh 
29None.giffile://--> 
30None.gif</script>

11.ACCESS数据库连接:

 1None.gif<%
 2None.gifoption explicit
 3None.gifdim startime,endtime,conn,connstr,db
 4None.gifstartime=timer()
 5None.gif'更改数据库名字
 6None.gifdb="data/dvBBS5.mdb"
 7None.gifSet conn = Server.createObject("ADODB.Connection")
 8None.gifconnstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
 9None.gif'如果你的服务器采用较老版本Access驱动,请用下面连接方*
10None.gif'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
11None.gifconn.Open connstr
12None.giffunction CloseDatabase
13None.gifConn.close
14None.gifSet conn = Nothing
15None.gifEnd Function
16None.gif%>
17None.gif

12.SQL数据库连接:

 1None.gif<%
 2None.gifoption explicit
 3None.gifdim startime,endtime,conn,connstr,db
 4None.gifstartime=timer()
 5None.gifconnstr="driver={SQL Server};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs" 
 6None.gifSet conn = Server.createObject("ADODB.Connection")
 7None.gifconn.Open connstr
 8None.giffunction CloseDatabase
 9None.gifConn.close
10None.gifSet conn = Nothing
11None.gifEnd Function
12None.gif%>
13None.gif

13.用键盘打开网页代码:

 1None.gif<script language="javascript">
 2None.giffunction ctlent(eventobject)
 3None.gif{
 4None.gifif((event.ctrlKey && window.event.keyCode==13)||(event.altKey && window.event.keyCode==83))
 5None.gif{
 6None.gifwindow.open('网址','','')
 7None.gif}
 8None.gif}
 9None.gif</script> 
10None.gif

这里是Ctrl+Enter和Alt+S的代码 自己查下键盘的ASCII码再换就行

14.让层不被控件复盖代码:

1None.gif<div z-Index:2><object ***></object></div> # 前面 
2None.gif<div z-Index:1><object ***></object></div> # 后面 
3None.gif<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>
4None.gif<div id="Layer1" style="position:absolute; top:50;width:200px; height:115px;z-index:1"><iframe height=100% width=100%></iframe></div>
5None.gif

15.动网FLASH广告代码:

1None.gif<object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/p& dot.gif ;flash.cab#version=5,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="http://www.macromedia.com/shockw dot.gif kwaveFlash";;; type="application/x-shockwave-f dot.gif height="60"></embed></object>

16.VBS弹出窗口小代码:
1None.gif<script language=vbscript>
2None.gifmsgbox"你还没有注册或登陆论坛","0","精品论坛"
3None.giflocation.href = "login.asp"
4None.gif</script>


16.使用FSO修改文件特定内容的函数

None.giffunction FSOchange(filename,Target,String)
None.gif
Dim objFSO,objCountFile,FiletempData
None.gif
Set objFSO = Server.createObject("Scripting.FileSystemObject")
None.gif
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
None.gifFiletempData 
= objCountFile.ReadAll
None.gifobjCountFile.Close
None.gifFiletempData
=Replace(FiletempData,Target,String)
None.gif
Set objCountFile=objFSO.createTextFile(Server.MapPath(filename),True)
None.gifobjCountFile.Write FiletempData 
None.gifobjCountFile.Close
None.gif
Set objCountFile=Nothing
None.gif
Set objFSO = Nothing
None.gif
End Function
None.gif

17.使用FSO读取文件内容的函数

None.giffunction FSOFileRead(filename)
None.gif
Dim objFSO,objCountFile,FiletempData
None.gif
Set objFSO = Server.createObject("Scripting.FileSystemObject")
None.gif
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
None.gifFSOFileRead 
= objCountFile.ReadAll
None.gifobjCountFile.Close
None.gif
Set objCountFile=Nothing
None.gif
Set objFSO = Nothing
None.gif
End Function

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

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

20.使用FSO添加文件新行的函数

None.giffunction FSOappline(filename,Linecontent)
None.gif
dim fso,f
None.gif
set fso = server.createObject("scripting.filesystemobject")
None.gif
if not fso.fileExists(server.mappath(filename)) then exit function
None.gif
set f = fso.opentextfile(server.mappath(filename),8,1)
None.giff.write 
chr(13)&chr(10)&Linecontent
None.giff.close
None.gif
set f = nothing
None.gif
end function
None.gif

转载于:https://www.cnblogs.com/fantboy/archive/2005/09/07/231681.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值