100ASP实例大全
实例01-helloworld.asp
<%@ LANGUAGE = VBScript %>
<HTML>
<TITLE>
Hello World
</TITLE>
<BODY>
<%
'以下循环输出Hello World字符串,字体由小变大
for i=1 to 5
response.write "<font size=" & i & ">hello world</font><br>"
next
%>
</BODY>
</HTML>
实例02-Restrict.asp
<%@ Language=VBScript %>
<html>
<title>
本站主页
</title>
<body>
<%
'本例根据远程主机地址来进行判断,如果为本地
'地址则进入欢迎页面,否则显示出错信息.
dim address
address = request.servervariables("REMOTE_ADDR")
if address="127.0.0.21" then
'如果为本地,则显示欢迎页面.
response.write "你好,欢迎进入本站点."
else
'否则显示出错信息.
response.write "对不起,你无权查看内部站点."
end if
%>
</body>
</html>
实例03-CountDown.asp
<%@ Language=VBScript %>
<html>
<title>
倒记时间
</title>
<body>
<%
response.write "今天是"
response.write formatDateTime(Date(),1) & ","
'格式化为长日期格式输出显示
response.write " 离高考还有"
response.write "<font color=blue><u>"
'调用DateDiff函数,计算日期间隔.
response.write DateDiff("d",Date(),"01-07-07")
response.write "</font></u>"
response.write "天"
%>
</body>
</html>
实例04-WEBTEST.ASP
<HTML>
<HEAD>
<TITLE>测试WEB服务器</TITLE>
</HEAD>
<BODY>
<Script language=jscript runat=server>
response.write ("<table border=1>");
response.write ("<tr><td>脚本引擎</td><td>");
response.write (ScriptEngine()+"</td></tr>");
response.write ("<tr><td>编译版本</td><td>");
response.write (ScriptEngineBuildVersion()+"</td></tr>");
response.write ("<tr><td>主 版 本</td><td>");
response.write (ScriptEngineMajorVersion()+"</td></tr>");
response.write ("<tr><td>次 版 本</td><td>");
response.write (ScriptEngineMinorVersion()+"</td></tr>");
response.write ("</table>");
</script>
<Script language=vbscript runat=server>
response.write "<table border=1>"
response.write "<tr><td>脚本引擎</td><td>"
response.write ScriptEngine() & "</td></tr>"
response.write "<tr><td>编译版本</td><td>"
response.write ScriptEngineBuildVersion() & "</td></tr>"
response.write "<tr><td>主 版 本</td><td>"
response.write ScriptEngineMajorVersion() & "</td></tr>"
response.write "<tr><td>次 版 本</td><td>"
response.write ScriptEngineMinorVersion() & "</td></tr>"
response.write "</table>"
</script>
</body>
实例05-Random.asp
<%@ LANGUAGE = VBScript %>
<html>
<title>
生成随机字符串
</title>
<body>
<%
Function gen_key(digits)
'定义并初始化数组
dim char_array(80)
'初始化数字
For i = 0 To 9
char_array(i) = CStr(i)
Next
'初始化大写字母
For i = 10 To 35
char_array(i) = Chr(i + 55)
Next
'初始化小写字母
For i = 36 To 61
char_array(i) = Chr(i + 61)
Next
Randomize '初始化随机数生成器。
do while len(output) < digits
num = char_array(Int((62 - 0 + 1) * Rnd + 0))
output = output + num
loop
'设置返回值
gen_key = output
End Function
'把结果返回给浏览器
response.write "本实例生成的十三位随机字符串为:"
response.write "<center>"
response.write gen_key(13)
response.write "</center>"
%>
</body>
</html>
实例06-ChangeColor.asp
<%@ Language=VBScript %>
<html>
<title>
移动鼠标改变背景颜色
</title>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function MakeColor(ThisColor) {
document.bgColor = ThisColor;
}
//-->
</SCRIPT>
<center>
<table cellspacing=2 Border="0">
<tr>
<%
Dim I1, I2, I3 ' Looping variables for RGB Color
For I1 = 0 to 15 step 3
For I2 = 0 to 15 step 3
For I3 = 0 to 15 step 3
Color = Hex(I1) & Hex(I1) & Hex(I2) & Hex(I2) & Hex(I3) & Hex(I3)
%>
<td bgcolor="#<%=Color%>">
<a href="#" LANGUAGE=javascript OnMouseOver="return MakeColor('#<%=Color%>');">
<img src="clear.gif" width=10 height=10 border="0"></a>
</td>
<%
Next
Next
%>
</tr>
<tr>
<%
Next
%>
</tr>
</table>
</center>
</html>
实例07-Login.asp
<HTML>
<BODY>
<TITLE>
用户登录
</TITLE>
<%
if Request.Form.Count=0 then
%>
请输入用户名和密码
<FORM ACTION="login.asp" METHOD="post">
<Table border=0>
<tr><td>用户名:</td>
<td><INPUT TYPE=text NAME=username VALUE=""></td>
</tr>
<tr><td>密码:</td>
<td><INPUT TYPE=password NAME=password VALUE=""></td>
</tr>
</Table>
<INPUT TYPE=Submit VALUE=确认提交>
<INPUT TYPE=reset VALUE=重新输入>
</FORM>
<%else%>
<%
Dim user
dim pwd
user=Request.Form("username")
pwd=Request.Form("password")
if user="fenfang" then
if pwd="1234" then
Response.write "用户登录成功"
else
Response.write "用户密码无效"
end if
else
本文地址:http://www.45fan.com/a/question/67207.html