一些ASP初学者常用的代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

一些ASP初学者常用的代码1.获得系统时间:%=now()%2.取得来访用的IP:%=request.serverVariables(remote_host)%3.获得系统,浏览器版本:scriptwindow.document.write(版本:+navigator.appName+navigator.appVersion+browser.)/script4.去除IE混动条:bodyscroll=nobodystyle=overflow-y:hidden5.进入网站,跳出广告:scriptlanguage=Javascript!--!--注意更改文件所在路径--window.open(''=200,width=300,top=0,left=30'');//--/script6.随机数:%randomize%%=(int(rnd()*n)+1)%N为可改变数7.向上混动代码:marqueedirection=upscrolldelay=200style=font-size:9pt;color:#FF0000;line-height:150%;font-style:italic;font-weight:boldscrollamount=2width=206height=207bgcolor=#FFFF00hhhhhhhhhhhhhhhhhhh/marquee8.自动关闭网页:scriptLANGUAGE=Javascript!--setTimeout(''window.close();'',10000);//60秒后关闭//--/scriptpalign=center本页10秒后自动关闭,请注意刷新页面/p9.随机背景音乐:%randomize%bgsoundsrc=mids/%=(int(rnd()*60)+1)%.midloop=-1可以修改数字,限制调用个数,我这里是60个.10.自动刷新本页面:script!--varlimit=0:10if(document.images){varparselimit=limit.split(:)parselimit=parselimit[0]*60+parselimit[1]*1}functionbeginrefresh(){if(!document.images)returnif(parselimit==1)window.location.reload()else{parselimit-=1curmin=Math.floor(parselimit/60)cursec=parselimit%60if(curmin!=0)curtime=curmin+分+cursec+秒后重刷本页!elsecurtime=cursec+秒后重刷本页!window.status=curtimesetTimeout(beginrefresh(),1000)}}window.onload=beginrefreshfile://--/script11.ACCESS数据库连接:%optionexplicitdimstartime,endtime,conn,connstr,dbstartime=timer()'更改数据库名字db=data/dvBBS5.mdbSetconn=Server.CreateObject(ADODB.Connection)connstr=Provider=Microsoft.Jet.OLEDB.4.0;DataSource=&Server.MapPath(db)'如果你的服务器采用较老版本Access驱动,请用下面连接方法'connstr=driver={MicrosoftAccessDriver(*.mdb)};dbq=&Server.MapPath(db)conn.OpenconnstrfunctionCloseDatabaseConn.closeSetconn=NothingEndFunction%12.SQL数据库连接:%optionexplicitdimstartime,endtime,conn,connstr,dbstartime=timer()connstr=driver={SQLServer};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbsSetconn=Server.CreateObject(ADODB.Connection)conn.OpenconnstrfunctionCloseDatabaseConn.closeSetconn=NothingEndFunction%13.用键盘打开网页代码:scriptlanguage=Javascriptfunctionctlent(eventobject){if((event.ctrlKey&&window.event.keyCode==13)||(event.altKey&&window.event.keyCode==83)){window.open('网址','','')}}/script这里是Ctrl+Enter和Alt+S的代码自己查下键盘的ASCII码再换就行14.让层不被控件复盖代码:divz-Index:2object***/object/div#前面divz-Index:1object***/object/div#后面divid=Layer2style=position:absolute;top:40;width:400px;height:95px;z-index:2tableheight=100%width=100%bgcolor=#ff0000trtdheight=100%width=100%/td/tr/tableiframewidth=0height=0/iframe/divdivid=Layer1style=position:absolute;top:50;width:200px;height:115px;z-index:1iframeheight=100%width=100%/iframe/div15.动网FLASH广告代码:objectclassid=clsid27CDB6E-AE6D-11cf-96B8-444553540000codebase==5,0,0,0width=468height=60paramname=movievalue=images/yj16d.swfparamname=qualityvalue=highembedsrc=images/dvbanner.swfquality=highpluginspage==ShockwaveFlash;;;type=application/x-shockwave-flashwidth=468height=60/embed/object16.VBS弹出窗口小代码:scriptlanguage=vbscriptmsgbox你还没有注册或登陆论坛,0,精品论坛location.href=login.asp/script16.使用FSO修改文件特定内容的函数functionFSOchange(filename,Target,String)DimobjFSO,objCountFile,FiletempDataSetobjFSO=Server.CreateObject(Scripting.FileSystemObject)SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)FiletempData=objCountFile.ReadAllobjCountFile.CloseFiletempData=Replace(FiletempData,Target,String)SetobjCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)objCountFile.WriteFiletempDataobjCountFile.CloseSetobjCountFile=NothingSetobjFSO=NothingEndFunction17.使用FSO读取文件内容的函数functionFSOFileRead(filename)DimobjFSO,objCountFile,FiletempDataSetobjFSO=Server.CreateObject(Scripting.FileSystemObject)SetobjCountFile=objFSO.OpenTextFile(Server.MapPath(filename),1,True)FSOFileRead=objCountFile.ReadAllobjCountFile.CloseSetobjCountFile=NothingSetobjFSO=NothingEndFunction18.使用FSO读取文件某一行的函数functionFSOlinedit(filename,lineNum)iflinenum1thenexitfunctiondimfso,f,temparray,tempcntsetfso=server.CreateObject(scripting.filesystemobject)ifnotfso.fileExists(server.mappath(filename))thenexitfunctionsetf=fso.opentextfile(server.mappath(filename),1)ifnotf.AtEndofStreamthentempcnt=f.readallf.closesetf=nothingtemparray=split(tempcnt,chr(13)&chr(10))iflineNumubound(temparray)+1thenexitfunctionelseFSOlinedit=temparray(lineNum-1)endifendifendfunction19.使用FSO写文件某一行的函数functionFSOlinewrite(filename,lineNum,Linecontent)iflinenum1thenexitfunctiondimfso,f,temparray,tempCntsetfso=server.CreateObject(scripting.filesystemobject)ifnotfso.fileExists(server.mappath(filename))thenexitfunctionsetf=fso.opentextfile(server.mappath(filename),1)ifnotf.AtEndofStreamthentempcnt=f.readallf.closetemparray=split(tempcnt,chr(13)&chr(10))iflineNumubound(temparray)+1thenexitfunctionelsetemparray(lineNum-1)=lineContentendiftempcnt=join(temparray,chr(13)&chr(10))se

1 / 32
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功