<html>
    <head>
    </head>
    <body>
    <script type="text/vbscript">
    document.write("Hello from VBScript!")
    </script>
    </body>
</html><!--在html中插入VBScript-->

关于在head中载入还是在body中载入的问题,与js一样

dim name 
name=some value

//声明变量后赋值

name=some value
//不声明直接赋值

vbs中不等于为<>,取模为Mod,逻辑运算Not、Or、And,字符串拼接&

//Sub,无返回值
Sub 
  mysub(argument1,argu
ment2)
some statements 
End Sub
//调用
Call MyProc(argument)
//Function,有返回值
Function 
  myfunction(argument1,argu
ment2) 
some statements
myfunction=some value 
End Function
//调用
name = findname()
//如果语句的例子
if payment="Cash" then
msgbox "You are going to pay 
cash!"
elseif payment="Visa" then
msgbox "You are going to pay with 
visa."
elseif payment="AmEx" then
msgbox "You are going to pay with 
American Express."
else
msgbox "Unknown method of 
payment."
end If
//开关语句的例子
select case payment
case "Cash"
msgbox "You are going to pay cash"
case "Visa"
msgbox "You are going to pay with 
visa"
case "AmEx"
msgbox "You are going to pay with 
American Express"
case Else
msgbox "Unknown method of 
payment"
end select
//For循环
For i=2 To 10 Step 2 
some code
Next
//While循环
i=0
do while i < 10
document.write(i & "<br />")
i=i+1
loop
//vbs的弹窗
<script type="text/vbscript"> 
Function myPopup_OnClick() 
MsgBox "Hello there!", 1, 
"Greeting Popup“
End Function 
</script>
<form> 
<input type="button" value="Click 
Me!" name="myPopup" />
</form> 
Web实践课程记录4
弹窗效果

ASP文件的内容大体上看与HTML无异,只不过ASP文件中<% %>之间包含的部分可以使vbs代码,由服务器执行

<%@ language="javascript"%> 
<html>
<body> 
<%
Response.Write("Hello 
World!") 
%> 
</body>
</html>
<!--由此可见,ASP也是可以用js写的,不过不要忘记js大小写敏感-->
<!--get请求-->
<body>
Welcome
<%
response.write(request.querystring("
fname"))
response.write(" " & 
request.querystring("lname"))
%>
</body>

<!--post请求-->
<body>
Welcome
<%
response.write(request.form("fname
"))
response.write(" " & 
request.form("lname"))
%>
</body>
<!--ASP中调用inc“头文件”-->
<html> 
<body> 

<h2>The time is:</h2>
<p><!--#include file="time.inc"--></p>
</body> 
</html>

time.inc
<% Response.Write(Time) %>
<!--ASP格式化输出文本-->
<html>
<body>
<%
response.write("<h2>您可以使用 HTML 标签来格式
化文本</h2>")

response.write("<p style='color:#0000ff'>这段文本
的样式是通过 style 属性添加的。</p>")
%>
</body>
</html>
<!--ASP处理form-->
<html>
<%
dim cars
cars=Request.Form("cars")
%>
<body>
<form action="/example/aspe/demo_aspe_radiob.asp" method="post">
<p>请选择您喜欢的汽车:</p>
<input type="radio" name="cars"
<%if cars="Volvo" then Response.Write("checked")%>
value="Volvo">Volvo</input>
<br />
<input type="radio" name="cars"
<%if cars="Saab" then Response.Write("checked")%>
value="Saab">Saab</input>
<br />
<input type="radio" name="cars"
<%if cars="BMW" then Response.Write("checked")%>
value="BMW">BMW</input>
<br /><br />
<input type="submit" value="提交" />
</form>
<%
if cars<>"" then
Response.Write("<p>您喜欢的汽车是" & cars & "</p>")
end if
%>
</body>
</html>
上面form代码的实际效果
<html>
<body>
<p>
<b>您正在通过这款浏览器访问我们的站点:</b>
<%Response.Write(Request.ServerVariables("http_user_agent"))%>
</p>
<p>
<b>您的 IP 地址是:</b>
<%Response.Write(Request.ServerVariables("remote_addr"))%>
</p>
<p>
<b>IP 地址的 DNS 查询是:</b>
<%Response.Write(Request.ServerVariables("remote_host"))%>
</p>
<p>
<b>调用该页面所用的方法是:</b>
<%Response.Write(Request.ServerVariables("request_method"))% >
</p>
</body>
</html>
上面代码的效果
<!--ASP获取文件修改时间-->
<html>
<body>
<%
Set fs = 
Server.CreateObject("Scripting.FileSystemObject
")
Set rs = 
fs.GetFile(Server.MapPath("/example/aspe/dem
o_aspe_lastmodified.asp"))
modified = rs.DateLastModified
%>
本文件的最后修改时间是:
<%response.write(modified)
Set rs = Nothing
Set fs = Nothing
%>
</body>
</html>

AOD具有管理数据库的功能,由微软开发,可以帮助“翻译”数据库语言

<!--AOD连接数据库的两种方法-->
<!--DSN-less connection-->
<%
set 
conn=Server.CreateObject("ADOD
B.Connection")
conn.Provider="Microsoft.Jet.OLEDB.
4.0"
conn.Open 
"c:/webdata/northwind.mdb"
%>

<!--ODBC connection-->
<% set 
conn=Server.CreateObject("ADOD
B.Connection") 
conn.Open "northwind“
%>

问题排查:ODBC无法连接

<!--处理对象-->
<% 
set 
conn=Server.CreateObject("ADODB.C
onnection") 
conn.Provider="Microsoft.Jet.OLEDB.4.0" 
conn.Open "c:/webdata/northwind.mdb" 
set 
rs=Server.CreateObject("ADODB.reco
rdset") 
rs.Open "Customers", conn 

rs.Open "Select * from Customers", conn
%>
<!--从对象中获取数据-->
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
for each x in rs.fields
response.write(x.name)
response.write(" = ")
response.write(x.value)
next
%>

一个实用的例子

<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
do until rs.EOF
for each x in rs.Fields
Response.Write(x.name)
Response.Write(" = ")
Response.Write(x.value & "<br />") 
next
Response.Write("<br />")
rs.MoveNext
loop
rs.close
conn.close
%>
</body>
</html>
效果图

如果将其与表格结合呢?

<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers"
rs.Open sql, conn
%>
<table border="1" width="100%" bgcolor="#fff5ee">
<tr>
<%for each x in rs.Fields
response.write("<th align='left' bgcolor='#b0c4de'>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
效果图

如果再加上筛选功能呢

<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT DISTINCT Country FROM Customers ORDER BY Country"
rs.Open sql,conn
country=request.form("country")
%>
<form method="post">
Choose Country <select name="country">
<% do until rs.EOF
response.write("<option")
if rs.fields("country")=country then
response.write(" selected")
end if
response.write(">")
response.write(rs.fields("Country"))
rs.MoveNext
loop
rs.Close
set rs=Nothing %>
</select>
<input type="submit" value="Show customers">
</form>
<%
if country<>"" then
sql="SELECT Companyname,Contactname,Country FROM Customers WHERE country='" & country & "'"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn
%>
<table width="100%" cellspacing="0" cellpadding="2" border="1">
<tr>
<th>Companyname</th>
<th>Contactname</th>
<th>Country</th>
</tr>
<%
do until rs.EOF
response.write("<tr>")
response.write("<td>" & rs.fields("companyname") & "</td>")
response.write("<td>" & rs.fields("contactname") & "</td>")
response.write("<td>" & rs.fields("country") & "</td>")
response.write("</tr>")
rs.MoveNext
loop
rs.close
conn.Close
set rs=Nothing
set conn=Nothing%>
</table>
<% end if %>
</body>
</html>
效果图

利用AOD向数据库中插入数据

<html>
<body>
<form method="post" action="demo_add.asp">
<table>
<tr>
<td>CustomerID:</td>
<td><input name="custid"></td>
</tr><tr>
<td>Company Name:</td>
<td><input name="compname"></td>
</tr><tr>
<td>Contact Name:</td>
<td><input name="contname"></td>
</tr><tr>
<td>Address:</td>
<td><input name="address"></td>
</tr><tr>
<td>City:</td>
<td><input name="city"></td>
</tr><tr>
<td>Postal Code:</td>
<td><input name="postcode"></td>
</tr><tr>
<td>Country:</td>
<td><input name="country"></td>
</tr>
</table>
<br /><br />
<input type="submit" value="Add New"> 
<input type="reset" value="Cancel">
</form>
</body>
</html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
sql="INSERT INTO customers (customerID,companyname,"
sql=sql & "contactname,address,city,postalcode,country)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("custid") & "',"
sql=sql & "'" & Request.Form("compname") & "',"
sql=sql & "'" & Request.Form("contname") & "',"
sql=sql & "'" & Request.Form("address") & "',"
sql=sql & "'" & Request.Form("city") & "',"
sql=sql & "'" & Request.Form("postcode") & "',"
sql=sql & "'" & Request.Form("country") & "')"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else 
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
</body>
</html>

Lab4

练习1:在数据库中记录用户分数
–您将获得一个名为score.mdb的数据库
–数据表的内容是字段s_name和s_score
–在服务器上设置此数据库的DSN
–当测试人员按下提交按钮时,在数据库中记录测试人员的姓名和分数

练习2:显示所有分数
–添加代码以在测试表格的底部显示所有用户的历史分数

练习3:美化页面

练习4:高级要求
–按分数对结果排序
–在表格中显示分数列表
提示:您可以使用SQL的“排序”功能

分类: 计算机

Reason

在漫漫梦路上踽踽独行的人……

1 条评论

joy · 2022年11月13日 上午12:23

你是纯粹的sb

发表回复

Avatar placeholder