ASP

一些asp初学者常用的代码

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(”http://www.XXXXXX.com”,””,”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>

本文引用通告地址: [url]http://www.donews.net/msroom/services/trackbacks/47873.aspx[/url]

[点击此处收藏本文] 发表于 2004年07月22日 6:26 PM

msroom 发表于2004-07-22 6:31 PM IP: 218.77.12.*
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码再换就行

msroom 发表于2004-07-22 6:31 PM IP: 218.77.12.*
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=”http://download.macromedia.com/pub/shockwave/cabs/flashlash.cab#version=5,0,0,0″ width=”468″ height=”60″><param name=movie value=”images/yj16d”><param name=quality value=high><embed src=”images/dvbanner” quality=high pluginspage=”http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash”; type=”application/x-shockwave-flash” width=”468″ height=”60″></embed></object>
16.VBS弹出窗口小代码:
<script language=vbscript>
msgbox”你还没有注册或登陆论坛”,”0″,”精品论坛”
location.href = “login.asp”
</script>

msroom 发表于2004-07-22 6:31 PM IP: 218.77.12.*
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

msroom 发表于2004-07-22 6:32 PM IP: 218.77.12.*
[推荐]利用FSO取得BMP,JPG,PNG,GIF文件信息(大小,宽、高等)
<%
‘::: BMP, GIF, JPG and PNG :::

‘::: This function gets a specified number of bytes from any :::
‘::: file, starting at the offset (base 1) :::
‘::: :::
‘::: Passed: :::
‘::: flnm => Filespec of file to read :::
‘::: offset => Offset at which to start reading :::
‘::: bytes => How many bytes to read :::
‘::: :::
‘:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function GetBytes(flnm, offset, bytes)
Dim objFSO
Dim objFTemp
Dim objTextStream
Dim lngSize
on error resume next
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

‘ First, we get the filesize
Set objFTemp = objFSO.GetFile(flnm)
lngSize = objFTemp.Size
set objFTemp = nothing
fsoForReading = 1
Set objTextStream = objFSO.OpenTextFile(flnm, fsoForReading)
if offset > 0 then
strBuff = objTextStream.Read(offset – 1)
end if
if bytes = -1 then ‘ Get All!
GetBytes = objTextStream.Read(lngSize) ‘ReadAll
else
GetBytes = objTextStream.Read(bytes)
end if
objTextStream.Close
set objTextStream = nothing
set objFSO = nothing
end function

‘:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
‘::: :::
‘::: Functions to convert two bytes to a numeric value (long) :::
‘::: (both little-endian and big-endian) :::
‘::: :::
‘:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function lngConvert(strTemp)
lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256)))
end function
function lngConvert2(strTemp)
lngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256)))
end function

‘:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
‘::: :::
‘::: This function does most of the real work. It will attempt :::
‘::: to read any file, regardless of the extension, and will :::
‘::: identify if it is a graphical image. :::
‘::: :::
‘::: Passed: :::
‘::: flnm => Filespec of file to read :::
‘::: width => width of image :::
‘::: height => height of image :::
‘::: depth => color depth (in number of colors) :::
‘::: strImageType=> type of image (e.g. GIF, BMP, etc.) :::
‘::: :::
‘:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function gfxSpex(flnm, width, height, depth, strImageType)
dim strPNG
dim strGIF
dim strBMP
dim strType
strType = “”
strImageType = “(unknown)”
gfxSpex = False
strPNG = chr(137) & chr(80) & chr(78)
strGIF = “GIF”
strBMP = chr(66) & chr(77)
strType = GetBytes(flnm, 0, 3)
if strType = strGIF then ‘ is GIF
strImageType = “GIF”
Width = lngConvert(GetBytes(flnm, 7, 2))
Height = lngConvert(GetBytes(flnm, 9, 2))
Depth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)
gfxSpex = True
elseif left(strType, 2) = strBMP then ‘ is BMP
strImageType = “BMP”
Width = lngConvert(GetBytes(flnm, 19, 2))
Height = lngConvert(GetBytes(flnm, 23, 2))
Depth = 2 ^ (asc(GetBytes(flnm, 29, 1)))
gfxSpex = True
elseif strType = strPNG then ‘ Is PNG
strImageType = “PNG”
Width = lngConvert2(GetBytes(flnm, 19, 2))
Height = lngConvert2(GetBytes(flnm, 23, 2))
Depth = getBytes(flnm, 25, 2)
select case asc(right(Depth,1))
case 0
Depth = 2 ^ (asc(left(Depth, 1)))
gfxSpex = True
case 2
Depth = 2 ^ (asc(left(Depth, 1)) * 3)
gfxSpex = True
case 3
Depth = 2 ^ (asc(left(Depth, 1))) ‘8
gfxSpex = True
case 4
Depth = 2 ^ (asc(left(Depth, 1)) * 2)
gfxSpex = True
case 6
Depth = 2 ^ (asc(left(Depth, 1)) * 4)
gfxSpex = True
case else
Depth = -1
end select

else
strBuff = GetBytes(flnm, 0, -1) ‘ Get all bytes from file
lngSize = len(strBuff)
flgFound = 0
strTarget = chr(255) & chr(216) & chr(255)
flgFound = instr(strBuff, strTarget)
if flgFound = 0 then
exit function
end if
strImageType = “JPG”
lngPos = flgFound + 2
ExitLoop = false
do while ExitLoop = False and lngPos < lngSize

do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop

if ExitLoop = False then
Width = -1
Height = -1
Depth = -1
else
Height = lngConvert2(mid(strBuff, lngPos + 4, 2))
Width = lngConvert2(mid(strBuff, lngPos + 6, 2))
Depth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8)
gfxSpex = True
end if

end if
end function

‘:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
‘::: Test Harness :::
‘:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

‘ To test, we’ll just try to show all files with a .GIF extension in the root of C:
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objF = objFSO.GetFolder(“c:\”)
Set objFC = objF.Files
response.write “<table border=””0″” cellpadding=””5″”>”
For Each f1 in objFC
if instr(ucase(f1.Name), “.GIF”) then
response.write “<tr><td>” & f1.name & “</td><td>” & f1.DateCreated & “</td><td>” & f1.Size & “</td><td>”
if gfxSpex(f1.Path, w, h, c, strType) = true then
response.write w & ” x ” & h & ” ” & c & ” colors”
else
response.write ” ”
end if
response.write “</td></tr>”
end if
Next
response.write “</table>”
set objFC = nothing
set objF = nothing
set objFSO = nothing

%>

msroom 发表于2004-07-22 6:32 PM IP: 218.77.12.*
24.点击返回上页代码:
<form>
<p><input TYPE=”button” VALUE=”返回上一步” ONCLICK=”history.back(-1)”></p>
</form>
24.点击刷新代码:
<form>
<p><input TYPE=”button” VALUE=”刷新按钮一” ONCLICK=”ReloadButton()”></p>
</form>
<script language=”JavaScript”><!–
function ReloadButton(){location.href=”allbutton.htm”;}
// –></script>

24.点击刷新代码2:
<form>
<p><input TYPE=”button” VALUE=”刷新按钮二” onClick=”history.go(0)”> </p>
</form>

<form>
<p><input TYPE=”button” VALUE=”打开一个网站” ONCLICK=”HomeButton()”></p>
</form>
<script language=”JavaScript”><!–
function HomeButton(){location.href=”http://nettrain.126.com”;/}
// –></script>

25.弹出警告框代码:
<form>
<p><input TYPE=”button” VALUE=”弹出警告框” ONCLICK=”AlertButton()”></p>
</form>
<script language=”JavaScript”><!–
function AlertButton(){window.alert(“要多多光临呀!”);}
// –></script>

26.状态栏信息
<form>
<p><input TYPE=”button” VALUE=”状态栏信息” ONCLICK=”StatusButton()”></p>
</form>
<script language=”JavaScript”><!–
function StatusButton(){window.status=”要多多光临呀!”;}
// –></script>

27.背景色变换
<form>
<p><input TYPE=”button” VALUE=”背景色变换” onClick=”BgButton()”></p>
</form>
<script>function BgButton(){
if (document.bgColor==’#00ffff’)
{document.bgColor=’#ffffff’;}
else{document.bgColor=’#00ffff’;}
}
</script>

28.点击打开新窗口
<form>
<p><input TYPE=”button” VALUE=”打开新窗口” ONCLICK=”NewWindow()”></p>
</form>
<script language=”JavaScript”><!–
function NewWindow(){window.open(“http://www.mcmx.com”,””,”height=240,width=340,status=no,location=no,toolbar=no,directories=no,menubar=no”/);}
// –></script></body>

msroom 发表于2004-07-22 6:33 PM IP: 218.77.12.*
29.分页代码:
<%”本程序文件名为:Pages.asp%>
<%”包含ADO常量表文件adovbs.inc,可从”\Program Files\Common Files\System\ADO”目录下拷贝%>
<!–#Include File=”adovbs.inc”–>
<%”*建立数据库连接,这里是Oracle8.05数据库
Set conn=Server.CreateObject(“ADODB.Connection”)
conn.Open “Provider=msdaora.1;Data Source=YourSrcName;User ID=YourUserID;Password=YourPassword;”

Set rs=Server.CreateObject(“ADODB.Recordset”) ”创建Recordset对象
rs.CursorLocation=adUseClient ”设定记录集指针属性
”*设定一页内的记录总数,可根据需要进行调整
rs.PageSize=10

”*设置查询语句
StrSQL=”Select ID,姓名,住址,电话 from 通讯录 Order By ID”
rs.Open StrSQL,conn,adOpenStatic,adLockReadOnly,adCmdText
%>
<html>
<head>
<title>分页示例</title>
<script language=javascript>
//点击”[第一页]”时响应:
function PageFirst()
{
document.MyForm.CurrentPage.selectedIndex=0;
document.MyForm.CurrentPage.onchange();
}
//点击”[上一页]”时响应:
function PagePrior()
{
document.MyForm.CurrentPage.selectedIndex–;
document.MyForm.CurrentPage.onchange();
}
//点击”[下一页]”时响应:
function PageNext()
{
document.MyForm.CurrentPage.selectedIndex++;
document.MyForm.CurrentPage.onchange();
}
//点击”[最后一页]”时响应:
function PageLast()
{
document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;
document.MyForm.CurrentPage.onchange();
}
//选择”第?页”时响应:
function PageCurrent()
{ //Pages.asp是本程序的文件名
document.MyForm.action=’Pages.asp?Page=’+(document.MyForm.CurrentPage.selectedIndex+1)
document.MyForm.submit();
}
</script>
</head>
<body bgcolor=”#ffffcc” link=”#008000″ vlink=”#008000″ alink=”#FF0000″”>

<%IF rs.Eof THEN
Response.Write(“<font size=2 color=#000080>[数据库中没有记录!]</font>”)
ELSE
”指定当前页码
If Request(“CurrentPage”)=”” Then
rs.AbsolutePage=1
Else
rs.AbsolutePage=CLng(Request(“CurrentPage”))
End If

”创建表单MyForm,方法为Get
Response.Write(“<form method=Get name=MyForm>”)
Response.Write(“<p align=center><font size=2 color=#008000>”)
”设置翻页超链接
if rs.PageCount=1 then
Response.Write(“[第一页] [上一页] [下一页] [最后一页] “)
else
if rs.AbsolutePage=1 then
Response.Write(“[第一页] [上一页] “)
Response.Write(“[<a href=javascript:PageNext()>下一页</a>] “)
Response.Write(“[<a href=javascript:PageLast()>最后一页</a>] “)
else
if rs.AbsolutePage=rs.PageCount then
Response.Write(“[<a href=javascript:PageFirst()>第一页</a>] “)
Response.Write(“[<a href=javascript:PagePrior()>上一页</a>] “)
Response.Write(“[下一页] [最后一页] “)
else
Response.Write(“[<a href=javascript:PageFirst()>第一页</a>] “)
Response.Write(“[<a href=javascript:PagePrior()>上一页</a>] “)
Response.Write(“[<a href=javascript:PageNext()>下一页</a>] “)
Response.Write(“[<a href=javascript:PageLast()>最后一页</a>] “)
end if
end if
end if

”创建下拉列表框,用于选择浏览页码
Response.Write(“第<select size=1 name=CurrentPage onchange=PageCurrent()>”)
For i=1 to rs.PageCount
if rs.AbsolutePage=i then
Response.Write(“<option selected>”&i&”</option>”) ”当前页码
else
Response.Write(“<option>”&i&”</option>”)
end if
Next
Response.Write(“</select>页/共”&rs.PageCount&”页 共”&rs.RecordCount&”条记录</font><p>”)
Response.Write(“</form>”)

”创建表格,用于显示
Response.Write(“<table align=center cellspacing=1 cellpadding=1 border=1″)
Response.Write(” bordercolor=#99CCFF bordercolordark=#b0e0e6 bordercolorlight=#000066>”)

Response.Write(“<tr bgcolor=#ccccff bordercolor=#000066>”)

Set Columns=rs.Fields

”显示表头
For i=0 to Columns.Count-1
Response.Write(“<td align=center width=200 height=13>”)
Response.Write(“<font size=2><b>”&Columns(i).name&”</b></font></td>”)
Next
Response.Write(“</tr>”)
”显示内容
For i=1 to rs.PageSize
Response.Write(“<tr bgcolor=#99ccff bordercolor=#000066>”)
For j=0 to Columns.Count-1
Response.Write(“<td><font size=2>”&Columns(j)&”</font></td>”)
Next
Response.Write(“</tr>”)

rs.movenext
if rs.EOF then exit for
Next

Response.Write(“</table>”)

END IF
%>
</body>
</html>

msroom 发表于2004-07-22 6:33 PM IP: 218.77.12.*
<form>
<label&nbsp;for=&quot;check1&quot;>经常来这里</label>&nbsp;
<input&nbsp;type=&quot;CHECKBOX&quot;&nbsp;id=&quot;check1&quot;&nbsp;value=&quot;often&quot;&nbsp;name=&quot;checkoften&quot;>
<label&nbsp;for=&quot;check2&quot;>偶尔来看看</label>&nbsp;
<input&nbsp;type=&quot;CHECKBOX&quot;&nbsp;id=&quot;check2&quot;&nbsp;value=&quot;seldom&quot;&nbsp;name=&quot;checkseldom&quot;>
</form>

呵呵,不好意思,忘了说明,这个代码是显示复选框更容易点中。我们平常会发现复选框有时候只能准确的点击那个小框框,加入这段代码,点中跟在小框框后面的文字也可以选中!!!

msroom 发表于2004-07-22 6:34 PM IP: 218.77.12.*
验证合法EMAIL地址:
function IsValidEmail(email)
dim names, name, i, c
IsValidEmail = true
names = Split(email, “@”)
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr(“abcdefghijklmnopqrstuvwxyz_-.”, c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = “.” or Right(name, 1) = “.” then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), “.”) <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) – InStrRev(names(1), “.”)
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, “..”) > 0 then
IsValidEmail = false
end if

end function

msroom 发表于2004-07-22 6:34 PM IP: 218.77.12.*
Windows Media Player 播放器
<object id=MediaPlayer1
style=”LEFT: 0px; VISIBILITY: visible; POSITION: absolute; TOP: 0px;z-index:2″
codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701standby=

Loading
type=application/x-oleobject height=300 width=320
classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 VIEWASTEXT>
<param NAME=”URL” VALUE=”地址”>

<param name=”AudioStream” value=”-1″>
<param name=”AutoSize” value=”0″>
<param name=”AutoStart” value=”-1″>
<param name=”AnimationAtStart” value=”0″>
<param name=”AllowScan” value=”-1″>
<param name=”AllowChangeDisplaySize” value=”-1″>
<param name=”AutoRewind” value=”0″>
<param name=”Balance” value=”0″>
<param name=”BaseURL” value>
<param name=”BufferingTime” value=”5″>
<param name=”CaptioningID” value>
<param name=”ClickToPlay” value=”-1″>
<param name=”CursorType” value=”0″>
<param name=”CurrentPosition” value=”-1″>
<param name=”CurrentMarker” value=”0″>
<param name=”DefaultFrame” value>
<param name=”DisplayBackColor” value=”0″>
<param name=”DisplayForeColor” value=”16777215″>
<param name=”DisplayMode” value=”0″>
<param name=”DisplaySize” value=”4″>
<param name=”Enabled” value=”-1″>
<param name=”EnableContextMenu” value=”-1″>
<param name=”EnablePositionControls” value=”0″>
<param name=”EnableFullScreenControls” value=”0″>
<param name=”EnableTracker” value=”-1″>
<param name=”InvokeURLs” value=”-1″>
<param name=”Language” value=”-1″>
<param name=”Mute” value=”0″>
<param name=”PlayCount” value=”1″>
<param name=”PreviewMode” value=”0″>
<param name=”Rate” value=”1″>
<param name=”SAMILang” value>
<param name=”SAMIStyle” value>
<param name=”SAMIFileName” value>
<param name=”SelectionStart” value=”-1″>
<param name=”SelectionEnd” value=”-1″>
<param name=”SendOpenStateChangeEvents” value=”-1″>
<param name=”SendWarningEvents” value=”-1″>
<param name=”SendErrorEvents” value=”-1″>
<param name=”SendKeyboardEvents” value=”0″>
<param name=”SendMouseClickEvents” value=”0″>
<param name=”SendMouseMoveEvents” value=”0″>
<param name=”SendPlayStateChangeEvents” value=”-1″>
<param name=”ShowCaptioning” value=”0″>
<param name=”ShowControls” value=”-1″>
<param name=”ShowAudioControls” value=”-1″>
<param name=”ShowDisplay” value=”0″>
<param name=”ShowGotoBar” value=”0″>
<param name=”ShowPositionControls” value=”-1″>
<param name=”ShowStatusBar” value=”-1″>
<param name=”ShowTracker” value=”-1″>
<param name=”TransparentAtStart” value=”-1″>
<param name=”VideoBorderWidth” value=”0″>
<param name=”VideoBorderColor” value=”0″>
<param name=”VideoBorder3D” value=”0″>
<param name=”Volume” value=”70″>
<param name=”WindowlessVideo” value=”0″>
</object>

msroom 发表于2004-07-22 6:35 PM IP: 218.77.12.*
RealPlayer 播放器
<object id=video1 classid=” clasid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA”
width=320 height=240 align=”middle”>
<param name=”controls” value=”inagewindow”>
<param name=”console” value=”chicp1″>
<param name=”autostar” value=”true”>
<param name=”src” value=”地址”>
<embed
src=”地址”
type=”audio/x-pn-realaudio-plugin” console=”chip1″
controls=”imagewindow” width=320 height=240 autostart=true align=”middle”>
</embed>
</object>

msroom 发表于2004-07-22 6:35 PM IP: 218.77.12.*
问题:如何保护自己的ASP源代码不泄露?

  答:下载微软的windows script encoder,对ASP的脚本和客户端javascript、vbscript脚本进行加密。客户端脚本加密后,只有ie5以上的版本才能执行,服务器端脚本加密后,只有服务器上安装有script engine 5(装ie5即可)才能解释执行。

  问题:为什么global.asa文件总是不起作用?

  答:只有把global.asa文件放在web发布目录某个站点的根目录下它才有效,放在发布目录的某个子目录下不起作用。另外,也可以使用iis4的internet service manager把某个子目录设置为站点。

  问题:为什么ASP文件总不解释执行?

  答:在iis服务器上没有给ASP文件以脚本解释的权限,所以ASP文件没有被web服务器作为脚本代码进行解释执行,而被当成一般页面文件了。建议在web发布目录中建立一个ASP目录,把所有ASP文件存放在此目录下,把ASP目录赋予脚本解释权限。

  问题:ASP文件中使用response.redirect(url)时导致错误“the http headers are already written to the client browser. any http header modifications must be made before writing page content”,请问如何解决?

  答:此错误为http标题在写入页内容之后,写到了客户浏览器中。任何http标题的修改必须在写入页内容之前进行,解决的方法为在ASP文件最开头加入response.buffer = true,在文件的结尾加入response.flush。

  问题:为什么session有时候会消失?

  答:session很像临时的cookie,只是其信息保存在服务器上(客户机上保存的是sessionid)。session变量消失有几种可能,如:使用者的浏览器不接受cookie,因为session依赖于cookie才能跟踪用户;session在一段时间后过期了,缺省为20分钟,如果希望更改,可以通过设置microsoft management console的web directory→properties→virtual directory→application settings→configuration→app options→session timeout选项来改变session的超时时间,也可以在ASP脚本中设定,如session.timeout=60,可设定超时时间为60分钟。

  问题:怎样才能知道访问者的一些信息?

  答:通过request.servervariables(″http—user—agent″)获得访问者浏览器的类型;request.servervariables(″remote—addr″)可获得访问者的ip地址;而访问者的语言环境可通过request.servervariables(″http—accept—language″)来获得。

  问题:怎样才能将query string从一个ASP文件传送到另一个ASP文件?

  答:前一个ASP文件加入下列代码:response.redirect(″second.ASP?″&request.servervariables(″query—string″))即可。

  问题:ASP中如何控制cookies?

  答:若想写入cookies可用:response.cookies(″待写入的coookies名称″)=待写入数据。读取cookies则使用:读取数据=request.cookies(″待读的cookies名称″)。

  注意,写入cookies的response.cookies程序段必须放在〈html〉标记之前,且不可以有任何的其它html代码。另外,cookies中必须使用expires设定有效期,cookies才能真正地写入客户端硬盘中,否则只是临时的。

  问题:怎样实现用ASP发送邮件?

  答:用户需装上windows nt option pack的smtp service功能。实现代码如下:

  〈%

  set mail = server.createobject(″cdonts.newmail″)

  mail.to =″[email]abc@xxx.com[/email]″

  mail.from =″[email]yourmail@xxx.com[/email]″

  mail.subject =″主题″

  mail.body =″e-mail内容″

  mail.send

  %〉

  问题:ASP与数据库连接一定要在服务器端设置dsn吗?

  答:不一定,ASP与服务器的数据库连接有两种方法,一种为通过dsn建立连接,另一种不用dsn建立连接。通过dsn连接数据库需要服务器的系统管理员在服务器的控制面板中的odbc中设置一个dsn。如果没有在服务器上设置dsn,只要知道数据库文件名(比如access、paradox、foxpro的数据库)或者数据源名(如sqlserver的数据库)就可以访问数据库,直接提供连接所需的参数即可。

  连接代码如下:

  set conn=server.createobject(″adodb.connection″)

  connpath=″dbq=″&server.mappath(″yourtable.mdb″)

  conn.open″driver={microsoft access driver (?.mdb)};″&connpath

  set rs=conn.execute(″select?from authors″)

  问题:如何从一页到另一页传递变量?

  答:用hidden表单类型来传递变量。

  〈form method=″post″action=″mynextpage.ASP″〉

  〈% for each item in request.form %〉

  〈input namee=″〈%=item%〉″type=″hidden″

  value=″〈%=server.htmlencode(request.form(item)) %〉″〉

  〈% next %〉

  〈/form〉

  用session来保存变量。

  〈%session(″bh″)= request.form (″bh″)%〉

  用querystring保存变量。

  〈a herf=″action.ASP?bh=10″〉查询〈/a〉

  〈%request. querystring (″bh″)%〉

  问题:如何用ASP实现在线人数统计?

  答:在线人数是指一个时段内的访客人数统计,时间的长短是由设计者设定的。

  在这个时段内,各个不同ip访问本站点的总数,就是当前的线上人数。在ASP中,使用session对象来实现统计,实现代码如下:

  golobal.asa文件

  〈script language=″vbscript″runat=″server″〉

  sub session—onstart

  application(″online″)=application(″online″)+1

  end sub

  sub session—onend

  application(″online″)=application(″online″)-1

  end sub

  sub application—onstard

  application(″online″)=0

  end sub

  sub application—onend

  application(″online″)=0

  end sub

  〈/script〉

  online.ASP文件内容

  〈% tmp=application(″online″)

  tmp=cstr(tmp)

  dim disp(20)

  dim images(20)

  dbbits=len(tmp)

  for i= 1 to dbbits

  disp(i)=left(right(tmp,i),i-(i-1))

  next

  for i=dbbits to 1 step -1

  images(i)=″〈img src=″&″[url]http://xxxx.com.cn/pic[/url]″&″/″&disp(i)&″.gif〉″

  response.write″document.write(′″&images(i)&″′);″

  next %〉

  问题:ASP程序运行的时间如何计算?

  答:确定ASP程序的执行时间的代码如下所示:

  〈%

  dim t1,t2

  t1=now()

  ′被检测的ASP代码

  t2=now()

  response.write″运行这段ASP代码用了″&cstr(cdbl((t2-t1)*24*60*60))&″秒″

  %〉

msroom 发表于2004-07-22 6:35 PM IP: 218.77.12.*
删除记录时弹出确认框:

<script LANGUAGE=”VBSCRIPT”>
a=msgbox(“真的要删除该记录吗?”,1,”注意”)
if a=1 then
location=”Dodelete.asp?id=<%=id%>” //指向执行删除的页面Dodelete.asp
else
history.go(-1)
end if
</script>

其中id=<%=id%>是指从表单中取得的数据编号,当然也可以是其他的东东。
这是我钱两天在坛子里提出的问题,感谢大家给出的解决方法,我觉得这条比较好用,希谢谢!

msroom 发表于2004-07-22 6:36 PM IP: 218.77.12.*
将查询数据时得到的记录关键字用红色显示:

<% =replace(RS(“字段X”),searchname,”<font color=#FF0000>” & searchname & “</font>”) %>

其中SEARCHNAME是查询时输入的关键字,这个效果就向大多数查询功能中常用的那样,也是在论坛中问人得来的答案,希望对和我一样的菜鸟有帮助,

这个论坛的人都很好,都很热心,I LIKE IT:)

msroom 发表于2004-07-22 6:37 PM IP: 218.77.12.*
我问的一些问题的答案
ASP打印
var strFeature=”height=360,width=500,status=no,toolbar=no,resizable=no,menubar=no,location=no”;
var aWin = window.open(“”,”Print”,strFeature);
aWin.document.open();
aWin.document.write(“<html>”);
aWin.document.write(“<head>”);
aWin.document.write(“<title>打印服务</title>”);
aWin.document.write(“</head>”);
aWin.document.write(“<body onload=’window.print();window.close();’>”);
aWin.document.write(“<img src=” + document.MVIMAGE.src +”>”);
aWin.document.write(“<font size=’0′>”);
aWin.document.write(“<br /><br />版权所有 郑州达维计算机技术有限公司</a> “);
aWin.document.write(“http://www.zzdw.com”;/);
aWin.document.write(“</font>”);
aWin.document.write(“</body>”);
aWin.document.write(“</html>”);
aWin.document.close();

输入框加背景色<input style=’background-color:Red’>在加入type=”xxx”可以为其它的控件加入背景颜色。

下拉菜单变背景色
<select name=”select”>
<option style=”background-color:#f0f0f0″>111111111</option>
<option style=”background-color:#cccccc”>111111111</option>
</select>
两个下拉表单相互关联
<form name=”doublecombo”>

<select name=”example” size=”1″ onChange=”redirect(this.options.selectedIndex)”>
<option>阳光在线</option>
<option>www.sunness.com</option>
<option>sunness.com</option>
</select>
<select name=”stage2″ size=”1″>
<option value=”http://www.80cn.com”;>阳光在线</option>
</select>
<input type=”button” name=”test” value=”Go!”
onClick=”go()”>
</p>
<script>
<!–
var groups=document.doublecombo.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()
group[0][0]=new Option(“阳光在线”,”http://www.sunness.com”;/)
group[1][0]=new Option(“阳光在线”,”http://www.donews.net/msroom/articles/<a%20target=”>http://www.sunness.com”;/”>
group[1][1]=new Option(“sunness”,”http://www.donews.net/msroom/articles/<a%20target=”>http://www.sunness.com”;/”>
group[1][2]=new Option(“sunness.com”,”http://www.donews.net/msroom/articles/<a%20target=”>http://www.sunness.com”;/”>
group[2][0]=new Option(“aaat”,”http://www.donews.net/msroom/articles/<a%20target=”>http://www.sunness.com”;/”>
group[2][1]=new Option(“bbb”,”http://www.donews.net/msroom/articles/<a%20target=”>http://www.sunness.com”;/”>
group[2][2]=new Option(“ddd”,”http://www.donews.net/msroom/articles/<a%20target=”>http://www.sunness.com”;/”>
group[2][3]=new Option(“ccc”,”http://www.donews.net/msroom/articles/<a%20target=”>http://www.sunness.com”;/”>

var temp=document.doublecombo.stage2
function redirect(x){
for (m=temp.options.length-1;m>0;m–)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}
function go(){
location=temp.options[temp.selectedIndex].value
}
//–>
</script>
</form>

msroom 发表于2004-07-22 6:37 PM IP: 218.77.12.*
网页技巧二十例

1. 如何在网页中加入注释
◆代码:< !– 这是注释 –>

2. 如何在网页中加入EMAIL链接并显示预定的主题
◆代码:< a href=”mailto:yourmail@xxx.xxx?Subject=你好”>Send Mail< /a>

3. 如何制作电子邮件表单
◆在<form>中输入Action=”youremail@XXX.XXX” ,提交采用POST方法。

4. 如何避免别人将你的网页放入他的框架(FRAME)中
◆在源代码中的<head>…< /HEAD>之间加入如下代码:
<s cript language=”javas cript”><!–
if (self!=top){top.location=self.location;}
–>< /s cript>

5. 如何自动加入最后修改日期
◆在源代码中的<body>…< /BODY>之间加入如下代码:
< s cript Language=”Javas cript”><!–
document.write(“Last Updated:”+document.lastModified);
–>< /s cript>

6. 如何让背景图象不滚动
◆代码:<body Background=”bg.gif” Bgproperties=”fixed” >
◆在Dreamweaver中用「Text」-「Custom Style」-「Edit Style Sheet」-「New」-Redefine HTML Tag中选择Body,然后在Background中的Attachment里选fixed

7. 如何将网页定时关闭
◆在源代码中的<body>后面加入如下代码:
< s cript LANGUAGE=”Javas cript”> <!–
setTimeout(‘window.close();’, 60000);
–> < /s cript>
在代码中的60000表示1分钟,它是以毫秒为单位的。

8. 将网页加入收藏夹
◆请使用如下代码:(注意标点符号)
< a href=’#’ onclick=”window.external.addFavorite(‘http://qiangwei.126.com&/#39;,’【梦想天空】qiangwei.126.com 各种网页工具教程DW、FLASH、FIREWORKS及CGI教学、聊天交友……’)” target=”_top”>将本站加入收藏夹< /a>

9. 如何定义网页的关键字(KeyWords)
◆格式如下:
< meta name=”keywords” content=”dreamweaver,flash,fireworks”>
content中的即为关键字,用逗号隔开
◆在Dreamweaver中用「Insert」-「Head」-KeyWords命令

10. 如何设置命令来关闭打开的窗口
◆在源代码中加入如下代码:
< a href=”/” onclick=”javas cript:window.close(); return false;”>关闭窗口< /a>

11. 如何在网页中加入书签,在页面内任意跳转
◆在源代码中需要插入书签的地方输入,在调用的地方输入Top,其中的top是你设定的书签名字。
◆在Dreamweaver中用菜单的「Insert」-「Name Anchor」命令插入书签,调用时,在Link中输入#top,top为书签名。

12. 如何为不支持框架的浏览器指定内容
◆在源代码中加入下面代码:
< BODY><noframes>本网页有框架结构,请下载新的浏览器观看< /noframes></ BODY>

13. 如何在网页中加入单个或几个空格
◆在源代码中输入 ,每个 之间请用空格分开。
◆在Dreamweaver中用<ctrl>+<shift>+<space>插入空格或任输几个字符,然后将其色彩设成背景的色彩!

14. 如何在网页中加入书签,在多个页面之间任意跳转
◆方法与上面类似,不过做链接时要在书签名前加上网页文件名,如:other.htm#top,这样一来就会跳转到other.htm页面中的top书签处。

15. 如何使表格(TABLE)没有边框线
◆将表格的边框属性:border=”0″

16. 如何隐藏状态栏里出现的LINK信息
◆请使用如下代码:
< a href=”http://qiangwei.126.com”;/ onMouseOver=”window.status=’none’;return true”>梦想天空< /a>

17. 如何定时载入另一个网页内容
◆在源代码中的<head>…< /HEAD> 加入如下代码:
< meta http-equiv=”refresh” content=”40;URL=http://qiangwei.126.com”>/
40秒后将自动[url]http://qiangwei.126.com[/url]所在的网页/

18. 如何为网页设置背景音乐
◆代码:< EMBED src=”music.mid” autostart=”true” loop=”2″ width=”80″ height=”30″ >
src:音乐文件的路径及文件名;
autostart:true为音乐文件上传完后自动开始播放,默认为false(否)
loop:true为无限次重播,false为不重播,某一具体值(整数)为重播多少次
volume:取值范围为”0-100″,设置音量,默认为系统本身的音量
starttime:”分:秒”,设置歌曲开始播放的时间,如,starttime=”00:10″,从第10开始播放
endtime: “分:秒”,设置歌曲结束播放的时间
width:控制面板的宽
height:控制面板的高
controls:控制面板的外观
controls=”console/smallconsole/playbutton/pausebutton/stopbutton/volumelever”
console:正常大小的面板
smallconsole:较小的面板
playbutton:显示播放按钮
pausebutton:显示暂停按钮
stopbutton:显示停止按钮
volumelever:显示音量调节按钮
hidden:为true时可以隐藏面板

19. 如何去掉链接的下划线
◆在源代码中的<head>…</head>之间输入如下代码:
<style type=”text/css”> <!–
a { text-decoration: none}
–> < /style>
◆在Dreamweaver中用「Text」-「Custom Style」-「Edit Style Sheet」-「New」-Redefine HTML Tag中选择a,然后在decoration中选中none

20. timeline中的layer走曲线
◆要使得timeline中的layer走曲线,你得先让他走出直线来,然后在最后一frame和第一frame中间的任何一frame上点右键,可以看到有个 add keyframe ,点一下,然后把你的layer移动到你要的位置,dw会自动生成曲线,good luck !

msroom 发表于2004-07-22 6:38 PM IP: 218.77.12.*
1.rs.open后的参数意义

RS.OPEN SQL,CONN,A,B
A: ADOPENFORWARDONLY(=0) 只读,且当前数据记录只能向下移动
ADOPENSTATIC(=3) 只读,当前数据记录可自由移动
ADOPENKEYSET(=1) 可读写,当前数据记录可自由移动
ADOPENDYNAMIC(=2) 可读写,当前数据记录可自由移动,可看到新增记录
B: ADLOCKREADONLY(=1) 默认值,用来打开只读记录
ADLOCKPESSIMISTIC(=2) 悲观锁定
ADLOCKOPTIMISTIC(=3) 乐观锁定
ADLOCKBATCHOPTIMISTIC(=4) 批次乐观锁定
2.文本提交自动分行
text=replace(text,chr(10),”<br />”)
text=replace(text,chr(13),”<br />”)
3.不同星期调用不同网页
<%response.buffer=false%>
<html><head>
<title>dailystuff.asp</title>
</head>
<body>
<%
whatweekday=Weekday(now())
select case whatweekday
case vbSunday
response.redirect “http://www.cnn.com”/
case vbMonday
response.redirect “http://www.activeserverpages.com”/
case vbTuesday
response.redirect “http://www.aspalliance.com”/
case vbWednesday
response.redirect “http://www.aspconvention.com”/
case vbThursday
response.redirect “http://www.aspmagazine.com”/
case vbFriday
response.redirect “http://www.dilbert.com”/
case vbSaturday
response.redirect “http://www.movielink.com”/
end select
%>
</body>
</html>
4.判断SQL语句是否执行成功?
利用err对象就可以了。
    sql=”insert into table(f1,f2) values(‘v1′,’v2’)”
    conn.execute sql
    if err.number0 then
        response.write “出错了:”& err.description err.clear
    else
        response.write “OK”
    end if   
5.session
<%
‘设置时间
session.timeout=1
‘结束一个
session.abandon
%>
6.关闭子窗口时刷新父窗口
在子窗口
<script language=”javascript”>
window.opener.location=”父窗口页面”
window.close()
</script>

msroom 发表于2004-07-22 6:39 PM IP: 218.77.12.*
我也来,目录树生成器。生成指定的目录结构。
如下:
:<%
‘目录树生成器,功能:生成指定的目录结构
‘dbpath=server.mappath(“.\xsadxx\assdd\bsdsdf\c\d\e\f\g\”)
dbpath=”c:\www\s\s\d\f\we\v\sdf\x\sf\x\sf\x\sf\s\f\sf\sdf\sfd\sdfs\”
function cutx(str,cx)
dim x,y,z
y=str
x=InStrRev(y,cx)
if x=len(y) then
y=left(y,len(y)-1)
x=InStrRev(y,cx)
end if
cutx=left(y,x)
end function

Function addx(str,mode)
dim x,y,z,m,n
x=str
z=mode
If right(x,1)<>”\” then
x=x&”\”
end if
If right(z,1)<>”\” then
z=z&”\”
end if
y=Replace(x,z,””)
m=instr(y,”\”)
m=left(y,m)
addx=z&m
end function
function findfolder(dbpath)
Set fso = CreateObject(“Scripting.FileSystemObject”)
If not fso.folderExists(dbpath) Then
findfolder(cutx(dbpath,”\”))
else
xx=dbpath
end if
Set fso1 = nothing
end function

function createfolder(truep,dbpath)
Set fsof = CreateObject(“Scripting.FileSystemObject”)
dbpath1=addx(dbpath,truep)
If not fsof.folderExists(dbpath1) then
‘Response.Write dbpath1
Fsof.Createfolder(dbpath1)
createfolder dbpath1,dbpath
else
createfolder=true
end if

Set fsof = nothing
end function
Function createtree(foder)
dim dbpath
dbpath=foder
findfolder dbpath
createfolder xx,dbpath
End Function
xx=””
‘Response.Write findfolder(dbpath)

‘Response.Write createfolder(xx,dbpath)
createtree dbpath

%>

msroom 发表于2004-07-22 6:40 PM IP: 218.77.12.*
最后贴一个本人写文本域JS预览代码.
<script language=JavaScript>
function preview()

{
var s=document.myform.content.value;
if(s.length>0)
{
pr=window.open(“”,””,” scrollbars=yes width=520 height=500 left=50 top=110″);
pr.document.write(‘<link href=style.css rel=stylesheet type=text/css>’);
var re=/ /g;
var ss=s.replace(re,””);
re=/</g;
ss=ss.replace(re,”&lt;”);
re=/>/g;
ss=ss.replace(re,”&gt;”);
re=/\n/g;
ss=ss.replace(re,”
“);
pr.document.write(ss);

}
else alert(‘没有可以预浏览的文本内容!’)
}
</script>
<form method=”POST” name=”myform” action=””>
<textarea rows=”10″ style=”table-layout:fixed;word-break:break-all” name=”content” cols=”90″>”
</textarea><br />
<input name=view onclick=preview() type=button value=预览页面>
</form>

msroom 发表于2004-07-22 6:42 PM IP: 218.77.12.*
我也来帖点:
—-特效字——————————————————
<span style=”COLOR: #000088; FILTER: glow(color=white,strength=1) shadow(color=dddddd,direction=130); LINE-HEIGHT: 23pt; POSITION: relative; WIDTH: 100%”> *** </span>

—-清空INPUT且选定———————————————
onClick=”Javascript:this.value=”” onFocus=”this.select()” onMouseOver=”this.focus()”

—-全屏显示页面——————————————–
<script language=”javascript”>
history.back();
chatroom=window.open(“chat.asp”,”chatroom”,”toolbar=no,status=no,resizable=yes”)
chatroom.moveTo(0,0);
chatroom.resizeTo(screen.availWidth,screen.availHeight);
chatroom.outerWidth=screen.availWidth;
chatroom.outerHeight=screen.availHeight;
</script>

——定时关闭窗口——————————————
<script language=”JavaScript”>
var tid=null;tid=setTimeout(‘window.close()’,300000);
</script>

——右键屏蔽———————————————-
<body oncontextmenu=self.event.returnValue=false>
——Boom!Boom!页——————————————
<script language=”JavaScript”>while (true){ window.open(“bomb.htm”,””,”fullscreen=yes,Status=no,scrollbars=no,resizable=no”);}</script>

———图片重新设置按钮—————————————
<script language=”jscript”>
function myreset()
{ document.login.reset();
document.login.focus();}
</script>
<img src=”image/reclear.gif” width=”69″ height=”20″ style=”cursor:hand” onfocus=”this.blur()” onclick=”myreset()”

msroom 发表于2004-07-22 6:48 PM IP: 218.77.12.*
<%
常用命令:
rs.movenext ‘将记录指针从当前的位置向下移一行
rs.moveprevious ‘将记录指针从当前的位置向上移一行
rs.movefirst ‘将记录指针移到数据表第一行
rs.movelast ‘将记录指针移到数据表最后一行
currentpage ‘第几页
rs.absoluteposition=N ‘将记录指针移到数据表第N行
rs.absolutepage=N ‘将记录指针移到第N页的第一行
rs.pagesize=N ‘设置每页为N条记录
rs.pagecount ‘根据 pagesize 的设置返回总页数
rs.recordcount ‘返回记录总数
rs.bof ‘返回记录指针是否超出数据表首端,true表示是,false为否
rs.eof ‘返回记录指针是否超出数据表末端,true表示是,false为否
rs.delete ‘删除当前记录,但记录指针不会向下移动
rs.addnew ‘添加记录到数据表末端
rs.update ‘更新数据表记录
%>
…………………………………………………………………………………….
--windows窗口打开代码开始--
<head>
<script language=JavaScript>
function about()
{
window.showModalDialog(“about.asp”,”ABOUT”,”dialogwidth:300px;dialogheight:150px;center:yes;status:no;scroll:no;help:no”);
}
</script>
</head>
<body>
<a href=’#’ onclick=”javascript:about();”><img src=images/list2.gif border=0 align=absMiddle ><font color=ffffff>
关于系统</font></a>
</body>
--windows窗口打开代码结束--
……………………………………………………………………………………………………….
有关分页显示的代码和注解
分页显示的代码和我的注解,不当之处请指正,另外有什么更好的分页的办法,麻烦贴一下。
<!–#include file=”conn.asp”–>
<html>
<body bgcolor=”#FFFFFF” text=”#000000″>
<table width=”60%” border=”1″ align=”center”>
<%
dim sql
msg_per_page = 4 ‘定义每页显示记录条数
sql = “select * from book order by time” ‘改成你自己的SQL语句
rs.cursorlocation = 3 ‘使用客户端游标,可以使效率提高
rs.pagesize = msg_per_page ‘定义分页记录集每页显示记录数
rs.open sql,conn,0,1
if err.number<>0 then ‘错误处理
response.write “数据库操作失败:” & err.description
err.clear

else

if not (rs.eof and rs.bof) then ‘检测记录集是否为空
totalrec = RS.RecordCount ‘totalrec:总记录条数
if rs.recordcount mod msg_per_page = 0 then
n = rs.recordcount\msg_per_page ‘n:总页数 ‘如果总页数/每页显示记录条数正好为整数
else
n = rs.recordcount\msg_per_page+1 ‘总页数/每页显示记录条数不为整数,表示有小于每页显示记录条数的数据出现,也应做为一页显示
end if
currentpage = request(“page”) ‘currentpage:当前页
‘以下防止在浏缆器中直接输入错误参数
If currentpage <> “” then
currentpage = cint(currentpage)’小数->整数

if currentpage < 1 then ‘小于1的数
currentpage = 1
end if

if err.number <> 0 then
err.clear
currentpage = 1
end if

else

currentpage = 1
End if

if currentpage*msg_per_page > totalrec and not((currentpage-1)*msg_per_page < totalrec)then ‘大于总页数
currentPage=1
end if

rs.absolutepage = currentpage ‘设置指针指向某页开头
rowcount = rs.pagesize ‘设置每一页的数据记录数
dim i
dim k
%>
<tr align=”center” valign=”middle”>
<td width=”50%”>e-mail</td>
<td width=”50%”>name</td>
</tr>
<%do while not rs.eof and rowcount > 0 ‘用rowcount定义循环次数即每一页的数据记录数%>
<tr align=”center” valign=”middle”>
<td width=”25%”><%=rs(“e-mail”)%></td>
<td width=”25%”><%=rs(“name”)%></td>
</tr>
<%
rowcount=rowcount-1
rs.MoveNext
loop
end if
end if
rs.close
set rs=nothing
%>
</table>

<table border=”5″ align=”center”>
<tr><td align=”center” valign=”middle”>
<%call listPages()%>
</td></tr>
</table>
</body>
</html>
<%
sub listPages()
if n <= 1 then exit sub ‘只有一页
%>

<p><span>>>
<%’第一页时%>
<%if currentpage = 1 then ‘第一页%>
<font color=darkgray face=”arial” >第一页 前一页</font>
<%else%>
<%’第一页至最后页时%>
<font color=black face=”arial”>
<a href=”<%=request.ServerVariables(“script_name”)%>?page=1″>Top</font></a>
<a href=”<%=request.ServerVariables(“script_name”)%>?page=<%=currentpage-1%>”><font color=black face=”arial” >前一页</a></font>
<%end if%>
<%’最后页时%>
<%if currentpage = n then%>
<font color=darkgray face=”arial” >下一页最后页</font>
<%else%>
<%’第一页至最后页时%>
<font color=black face=”arial” >
<a href=”<%=request.ServerVariables(“script_name”)%>?page=<%=currentpage+1%>”>下一页</a>
<a href=”<%=request.ServerVariables(“script_name”)%>?page=<%=n%>”>最后页</a></font>
<%end if%>

<font color=black face=”arial” >
Page:<%=currentpage%>/<%=n%>页<%=msg_per_page%>条/页 Total:<%=totalrec%>条</font></span></p>
<%end sub%>

<%

函数名称 函数功能
Cbool(string) 转换为布尔值
Cbyte(string) 转换为字节类型的值
Ccur(string) 转换为货币类值
Cdate(string) 转换为日前类型的值
Cdbl(string) 转换为双精度值
Cint(string) 转换为整数值
Clng(string) 转换为长整型的值
Csng(string) 转换为单精度的值
Cstr(var) 转换为字符串值
Str(var) 数值转换为字符串
Val(string) 字符串转换为数值
****** ******
****** ******
Abs(nmb) 返回数子的绝对值
Atn(nmb) 返回一个数的反正切
Cos(nmb) 返回一个角度的余炫值
Exp(nmb) 返回自然指数的次方值
Int(nmb) 返回数字的整形(进位)部份
Fix(nmb) 返回数字的整形(舍去)部份
Formatpercent(表达式) 返回百分比
Hex(nmb) 返回数据的16进制数
Log(nmb) 返回自然对数
Oct(nmb) 返回数字的8进制数
Rnd 返回大于“0”而小于“1”的随机数
Sgn(nmb) 判断一个数字的正负号
Sin(nmb) 返回角度的正铉值
Sqr(nmb) 返回数字的二次方根
Tan(nmb) 返回一个数的正切值
Asc(string) 返回ASCII字符串
Chr(charcode) 根据字符代码返回字符
Instr(string,searchstr) 返回被搜索字符串的第一个字符位置,string是字符串,searchstr是被搜索的字符串
InstrRev(string,searchstr) 同上,只是从右面开始搜索
Lcase(var) 把字符串变为小写
Left(string,nmb) 从string中返回从左面开始的nmb个字符串
Len(string) 返回字符串的长度
Ltrim(string) 截去字符串左边的空格
Filter(inputstrings,value) 返回字符串数组的字集,Inputstrings是字符串组,value是在数组中寻找的字符
Rtrim(string) 截去字符串右边的空格
Trim(string) 截去字符串前后空格
Mid(string,start,len) 在string中返回从start位置开始的len个字符
Replace(string,find,withstr) 在字符串string中,用withstr来替换find字符串
Right(string,nmb) 从string中返回从右面开始的nmb个字符串
Space(nmb) 返回指定空格的字符串
StrComp(string1,string2) 比较两个字符串
Ucase(string) 把字符串变为大写
****** ******
****** ******
Date() 返回当前系统日期
DateAdd(interval,nmb,date) 用一个基础时间返回指定增加了时间间隔的日期,interval是间隔类型,yyyy-年,m-月,d-日,h-小时,n-分。
DateDiff(interval,nmb1,nmb2) 返回两个时间间隔,interval的意思同上
Datevalue(date) 发挥Date中的日期部份
Day(date) 返回天数
FormatDatetime(date) 返回格式化为日期的表达式
Hour(time) 返回时间的小时数
Minute(time) 返回时间的分钟数
Month(date) 返回日期中的月份
Now() 返回系统的日期和时间
Second(time) 返回时间中的秒数
Time() 返回系统的当前时间
Weekday(date) 返回星期几
WeekdayName(date) 返回星期几的中文名
Year(date) 返回年份
IsArray(var) 判断一个变量是否是数组
IsDate(var) 判断一个变量是否是日期
IsNull(var) 判断一个变量是否为空
IsNumeric 判断表达式是否包含数值
IsObject(var) 判断一个变量是否是对象
TypeName(var) 返回变量的数据类型
****** ******
****** ******
Array(list) 返回数组
CreateObject(class) 创建一个对象
GetObject(pathfilename) 得到文件对象
Inputbox(prompt) 提供一个可供输入数据的对话框
LBound(arrayP 返回数组的最小索引
Msgbox(string) 输出一个消息框
Split(liststr) 从一个列表字符串中返回一个一维数组
Ubound(array) 返回数组的最大索引
%>

<%
‘+++++++++++++++++++++++++++++++++++++
‘◆模块名称: 公共翻页模块
‘◆文 件 名: TurnPage.asp
‘◆传入参数: Rs_tmp (记录集), PageSize (每页显示的记录条数)
‘◆输 出: 记录集翻页显示功能
‘+++++++++++++++++++++++++++++++++++++

Sub TurnPage(ByRef Rs_tmp,PageSize) ‘Rs_tmp 记录集 ; PageSize 每页显示的记录条数;
Dim TotalPage ‘总页数
Dim PageNo ‘当前显示的是第几页
Dim RecordCount ‘总记录条数
Rs_tmp.PageSize = PageSize
RecordCount = Rs_tmp.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo = Request.QueryString (“PageNo”)
‘直接输入页数跳转;
If Request.Form(“PageNo”)<>”” Then PageNo = Request.Form(“PageNo”)
‘如果没有选择第几页,则默认显示第一页;
If PageNo = “” then PageNo = 1
If RecordCount <> 0 then
Rs_tmp.AbsolutePage = PageNo
End If

‘获取当前文件名,使得每次翻页都在当前页面进行;
Dim fileName,postion
fileName = Request.ServerVariables(“script_name”)
postion = InstrRev(fileName,”/”)+1
‘取得当前的文件名称,使翻页的链接指向当前文件;
fileName = Mid(fileName,postion)
%>
<table border=0 width=’100%’>
<tr>
<td align=left> 总页数:<font color=#ff3333><%=TotalPage%></font>页
当前第<font color=#ff3333><%=PageNo%></font>页</td>
<td align=”right”>
<%If RecordCount = 0 or TotalPage = 1 Then
Response.Write “首页|前页|后页|末页”
Else%>
<a href=”<%=fileName%>?PageNo=1″>首页|</a>
<%If PageNo – 1 = 0 Then
Response.Write “前页|”
Else%>
<a href=”<%=fileName%>?PageNo=<%=PageNo-1%>”>前页|</a>
<%End If

If PageNo+1 > TotalPage Then
Response.Write “后页|”
Else%>
<a href=”<%=fileName%>?PageNo=<%=PageNo+1%>”>后页|</a>
<%End If%>

<a href=”<%=fileName%>?PageNo=<%=TotalPage%>”>末页</a>
<%End If%></td>
<td width=95>转到第
<%If TotalPage = 1 Then%>
<input type=text name=PageNo size=3 readonly disabled style=”background:#d3d3d3″>
<%Else%>
<input type=text name=PageNo size=3 value=”” title=请输入页号,然后回车>
<%End If%>页
</td>
</tr>
</table>
<%End Sub%>

  当然,大家可以把翻页的链接做成图片按钮,这样的话也面就更加美观了。
  调用方法:
  1、在程序开始或要使用翻页的地方包含翻页模块文件;
  2、定义变量:RowCount,每页显示的记录条数
  3、调用翻页过程:Call TurnPage(记录集,RowCount)
  4、在Do While 循环输出记录集的条件中加上” RowCount > 0 ” 条件
  5、在循环结束 “Loop前” 加上: RowCount = RowCount – 1

‘—————————————————–
调用范例:
文件名:News.asp
<%
Dim Conn,Rs_News
Set Conn = server.CreateObject(“ADODB.CONNECTION”)
Conn.Open “cpm”,”cpm”,”cpm”

Dim Sql
Sql = “Select * from News”
Set Rs_News = Server.CreateObject(“ADODB.RECORDSET”)
Rs_News.Open Sql,Conn,1,3 ‘获取的记录集

‘公共翻页模块开始%>
<!–#include file=../Public/TurnPage.asp–>
<%
Dim RowCount
RowCount = 10 ‘每页显示的记录条数
Call TurnPage(Rs_News,RowCount)
‘公共翻页模块结束%>

<table width=100%>
<tr>
<td>新闻编号</td>
<td>新闻标题</td>
<td>发布日期</td>
<tr>
<%
If Not Rs_News.eof
Do while Not Rs_News.eof and RowCount>0
%>
<tr>
<td><%=Rs_News(“ID”)%></td>
<td><%=Rs_News(“Name”)%></td>
<td><%=Rs_News(“Date”)%></td>
<tr>
<%
RowCount = RowCount – 1
Rs_News.MoveNext
Loop
End If
%>

asp启示移动到第n条
<%
set conn=server.createobject(“adodb.connection”)
conn.open “provider=microsoft.jet.oledb.4.0;data source=”&server.mappath(“data.mdb”0)
rs=conn.execute “select *from 信息”
n=12
rs.move n ‘移动到n条
rs.close
rs.activeconnection=nothing
conn.activeconnection=nothing
%>

分类: ASP

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部