<script type="text/javascript">google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("<s"+"cript type='text/javascript' s"+"rc='http://pagead2.googlesyndication.com/pagead/show_ads"+"."+"js'></scr"+"ipt>");</script>
首先,是HTML文件,为Test.asp,代码如下:

<%...@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<%...
if session("username")="" then
Response.Write("<script>alert('请登陆后在进行操作!');window.location='login.asp?reURL=Test.asp';</script>")
Response.End()
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>情景问答</title>

<style type="text/css">...
<!--

body {...}{
font-size: 12px;
color: #0066FF;
}

input {...}{
border: 1px solid #FFFFFF;
background-color: #EEEEEE;
left: 1px;
top: 1px;
right: 1px;
bottom: 1px;
clip: rect(10px,10px,10px,10px);
margin: 1px;
padding: 1px;
}

-->
</style>
</head>

<script language="javascript">...
<!--
function chkForm()

...{
var e = document.frm;
var it,flag,i;
flag = false;
for(i = 1;i<=10;i++)

...{
var it = eval("e.Question"+i);
var itLen = eval("e.Question"+i+".length");
for(var j = 0;j<itLen;j++)

...{
var itChk = eval("e.Question"+i+"["+j+"].checked");

if(itChk)

...{
flag = true;
break;
}
if(!itChk && j == itLen-1)

...{
flag = false;
break;
}
}
if(!flag)

...{
alert("请选择第"+i+"题答案");
return false;
}
}
if(!flag)

...{
alert("请选择第"+i+"题答案");
eval("e.Question"+i+".focus()");
return false;
}
return true;
}
-->
</script>
<body>
<div><strong>情景问答</strong></div>
<form name="frm" action="Test_do.asp" method="post" onsubmit="return(chkForm());">
<p><br />
1. 遗忘黯淡中的女主角叫什么名字?<br />
<label>
<input type="radio" name="Question1" value="A" />
A.</label>
Lan<br />
<label>
<input type="radio" name="Question1" value="B" />
B.</label>
Jenny<br /> <label>
<input type="radio" name="Question1" value="C" />
C.</label> Lucy</p>
<p>2. 音乐往事中酒吧的名字是什么?<br />
<label>
<input type="radio" name="Question2" value="A" />
A.</label>
遗忘<br />
<label>
<input type="radio" name="Question2" value="B" />
B.</label>
NV<br />
<label>
<input type="radio" name="Question2" value="C" />
C.</label>
如影随形</p>
<p>3.遗忘黯淡中的照片墙上有什么照片?<br />
<label>
<input type="radio" name="Question3" value="A" />
A.</label>
从前的女主人公<br />
<label>
<input type="radio" name="Question3" value="B" />
B.</label>
海边的风景<br />
<label>
<input type="radio" name="Question3" value="C" />
C.</label>
酒吧外景</p>
<p>4. 音乐往事中女主人公喝的酒叫什么名字?<br />
<label>
<input type="radio" name="Question4" value="A" />
A.</label>
红粉佳人<br />
<label>
<input type="radio" name="Question4" value="B" />
B.</label>
七色彩虹<br />
<label>
<input type="radio" name="Question4" value="C" />
C.</label>
蔚蓝海岸</p>
<p>5.遗忘黯淡中New Vision杂志的封面人物是谁?<br />
<label>
<input type="radio" name="Question5" value="A" />
A.</label> 玄斌<br />
<label>
<input type="radio" name="Question5" value="B" />
B.</label> Rain<br />
<label>
<input type="radio" name="Question5" value="C" />
C.</label> 张东健</p>
<p>6. 音乐往事中的唱片名字是什么?<br />
<label>
<input type="radio" name="Question6" value="A" />
A.</label>
BEWITCHED<br />
<label>
<input type="radio" name="Question6" value="B" />
B.</label>
WONDERFUL<br />
<label>
<input type="radio" name="Question6" value="C" />
C.</label>
BEAUTIFUL</p>
<p>7. 音乐往事中的酒吧墙壁上写着什么?<br />
<label>
<input type="radio" name="Question7" value="A" />
A.</label>
Love is beautiful<br />
<label><input type="radio" name="Question7" value="B" />
B.</label>
Truth is beautiful<br />
<label><input type="radio" name="Question7" value="C" />
C.</label>
Smile is beautiful</p>
<p>8. 音乐往事中的吧台上摆放着什么?<br />
<label><input type="radio" name="Question8" value="A" />
A.</label>
留声机<br />
<label><input type="radio" name="Question8" value="B" />
B.</label>
收音机<br />
<label><input type="radio" name="Question8" value="C" />
C.</label>
黑胶唱片</p>
<p>9. 音乐往事中男主人公的喜好是?<br />
<label><input type="radio" name="Question9" value="A" />
A.</label>
电影<br />
<label><input type="radio" name="Question9" value="B" />
B.</label>
摄影<br />
<label><input type="radio" name="Question9" value="C" />
C.</label>
烟草和音乐</p>
<p>10.凝固精彩中的主人公爱好什么?<br />
<label><input type="radio" name="Question10" value="A" />
A.</label>
旅游<br />
<label><input type="radio" name="Question10" value="B" />
B.</label>
摄影<br />
<label><input type="radio" name="Question10" value="C" />
C.</label>
上网</p>
<p><br />
<input type="submit" name="Submit" value="提交" />
<br />
</p>
</form>
</body>
</html>
下面是后台代码Test_do.asp,代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file="conn.asp" -->
<!-- #include file="function.asp" -->
<%
Response.CacheControl = "no-cache"
Response.Expires = -1
Response.ExpiresAbsolute=now()-1

if session("username")="" then
Response.Write("<script>alert('请登陆后在进行操作!');window.location='login.asp?reURL=Nv_Scene_Test.asp';</script>")
Response.End()
end if

'定义选项的最高分即总分
Const TOTALSCORE = 100
Const ITEMS = 10
'定义选项分数
Dim Result(9)
'第一题得分标准
Result(0) = "A|10|_|B|0|_|C|0"

'第二题得分标准
Result(1) = "A|0|_|B|10|_|C|0"

'第三题得分标准
Result(2) = "A|10|_|B|0|_|C|0"

'第四题得分标准
Result(3) = "A|0|_|B|0|_|C|10"

'第五题得分标准
Result(4) = "A|0|_|B|0|_|C|10"

'第六题得分标准
Result(5) = "A|10|_|B|0|_|C|0"

'第七题得分标准
Result(6) = "A|0|_|B|10|_|C|0"

'第八题得分标准
Result(7) = "A|10|_|B|0|_|C|0"

'第九题得分标准
Result(8) = "A|0|_|B|0|_|C|10"

'第十题得分标准
Result(9) = "A|0|_|B|10|_|C|0"

''第十一题得分标准
'Result(10) = "A|0|_|B|0|_|C|10"
'
''第十二题得分标准
'Result(11) = "A|0|_|B|10|_|C|0"
'
''第十三题得分标准
'Result(12) = "A|10|_|B|0|_|C|0"
'
''第十四题得分标准
'Result(13) = "A|0|_|B|10|_|C|0"
'
''第十五题得分标准
'Result(14) = "A|0|_|B|0|_|C|10"



If UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" Then
Call Chk_Post()
Dim i,total,selItem,summary,strDes,strOut
total = 0
For i = 0 To (ITEMS-1)
selVal = Trim(Request.Form("Question"&i+1))
arrItem = Split(Result(i),"|_|")
For j = 0 To Ubound(arrItem)
If selVal = Split(arrItem(j),"|")(0) Then
total = total + CInt(Split(arrItem(j),"|")(1))
selItem = selItem &"<li>Question"&i+1&":"&selVal&"</li>"&vbCrLf
End If
Next
Next
summary = FormatPercent(total/TOTALSCORE)
If (total/TOTALSCORE)>=0.6 Then
strDes = "正确率 "&summary&"<br>您已经顺利通过吧"
Else
strDes = "正确率 "&summary&"<br>很遗憾,您正确率还没有达到60%。请再来试试吧!<br><a href=Test.asp'>回在线问答页>></a>"
End If
strOut = "You have Selected these items below:<br>"&selItem&"<br>Total:"&total&"<br>您的正确率为:"&summary
strOut = strOut &"<br>"&strDes
str_sql = "SELECT Count(1) FROM UserInfo WHERE MemberId='"&Session("Id")&"'"
rowCount = DataConn.execute(str_sql)(0)
If rowCount > 0 Then'如果存在就更新个人信息
str_sql = "UPDATE UserInfo "
str_sql = str_sql &" SET Result = '"&FormatNumber(total/TOTALSCORE,2)&"'"
str_sql = str_sql &" ,ip = '"&Get_UserIp()&"'"
str_sql = str_sql &" ,AddTime = getdate()"
str_sql = str_sql &" WHERE MemberID= '"&Session("Id")&"'"
Else
str_sql = "INSERT INTO UserInfo( Result,MemberId,MemberName,ip) "
str_sql = str_sql &" VALUES('"& FormatNumber(total/TOTALSCORE,2)&"','"&Session("Id")&"','"&Session("Username")&"','"&Get_UserIp()&"')"
End If
DataConn.execute(str_sql)
End If


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>在线问答测试结果</title>
<style type="text/css">
<!--
body {
font-size: 12px;
color: #0066FF;
}
input {
border: 1px solid #FFFFFF;
background-color: #EEEEEE;
left: 1px;
top: 1px;
right: 1px;
bottom: 1px;
clip: rect(10px,10px,10px,10px);
margin: 1px;
padding: 1px;
}

-->
</style>
</head>

<body>
<%Response.Write(strOut)%>
</body>
</html>
<<script type="text/javascript">google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("<s"+"cript type='text/javascript' s"+"rc='http://pagead2.googlesyndication.com/pagead/show_ads"+"."+"js'></scr"+"ipt>");</script>"");
首先,是HTML文件,为Test.asp,代码如下:

<%...@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%...
if session("username")="" then
Response.Write("<script>alert('请登陆后在进行操作!');window.location='login.asp?reURL=Test.asp';</script>")
Response.End()
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>情景问答</title>
<style type="text/css">...
<!--
body {...}{
font-size: 12px;
color: #0066FF;
}
input {...}{
border: 1px solid #FFFFFF;
background-color: #EEEEEE;
left: 1px;
top: 1px;
right: 1px;
bottom: 1px;
clip: rect(10px,10px,10px,10px);
margin: 1px;
padding: 1px;
}
-->
</style>
</head>
<script language="javascript">...
<!--
function chkForm()
...{
var e = document.frm;
var it,flag,i;
flag = false;
for(i = 1;i<=10;i++)
...{
var it = eval("e.Question"+i);
var itLen = eval("e.Question"+i+".length");
for(var j = 0;j<itLen;j++)
...{
var itChk = eval("e.Question"+i+"["+j+"].checked");
if(itChk)
...{
flag = true;
break;
}
if(!itChk && j == itLen-1)
...{
flag = false;
break;
}
}
if(!flag)
...{
alert("请选择第"+i+"题答案");
return false;
}
}
if(!flag)
...{
alert("请选择第"+i+"题答案");
eval("e.Question"+i+".focus()");
return false;
}
return true;
}
-->
</script>
<body>
<div><strong>情景问答</strong></div>
<form name="frm" action="Test_do.asp" method="post" onsubmit="return(chkForm());">
<p><br />
1. 遗忘黯淡中的女主角叫什么名字?<br />
<label>
<input type="radio" name="Question1" value="A" />
A.</label>
Lan<br />
<label>
<input type="radio" name="Question1" value="B" />
B.</label>
Jenny<br /> <label>
<input type="radio" name="Question1" value="C" />
C.</label> Lucy</p>
<p>2. 音乐往事中酒吧的名字是什么?<br />
<label>
<input type="radio" name="Question2" value="A" />
A.</label>
遗忘<br />
<label>
<input type="radio" name="Question2" value="B" />
B.</label>
NV<br />
<label>
<input type="radio" name="Question2" value="C" />
C.</label>
如影随形</p>
<p>3.遗忘黯淡中的照片墙上有什么照片?<br />
<label>
<input type="radio" name="Question3" value="A" />
A.</label>
从前的女主人公<br />
<label>
<input type="radio" name="Question3" value="B" />
B.</label>
海边的风景<br />
<label>
<input type="radio" name="Question3" value="C" />
C.</label>
酒吧外景</p>
<p>4. 音乐往事中女主人公喝的酒叫什么名字?<br />
<label>
<input type="radio" name="Question4" value="A" />
A.</label>
红粉佳人<br />
<label>
<input type="radio" name="Question4" value="B" />
B.</label>
七色彩虹<br />
<label>
<input type="radio" name="Question4" value="C" />
C.</label>
蔚蓝海岸</p>
<p>5.遗忘黯淡中New Vision杂志的封面人物是谁?<br />
<label>
<input type="radio" name="Question5" value="A" />
A.</label> 玄斌<br />
<label>
<input type="radio" name="Question5" value="B" />
B.</label> Rain<br />
<label>
<input type="radio" name="Question5" value="C" />
C.</label> 张东健</p>
<p>6. 音乐往事中的唱片名字是什么?<br />
<label>
<input type="radio" name="Question6" value="A" />
A.</label>
BEWITCHED<br />
<label>
<input type="radio" name="Question6" value="B" />
B.</label>
WONDERFUL<br />
<label>
<input type="radio" name="Question6" value="C" />
C.</label>
BEAUTIFUL</p>
<p>7. 音乐往事中的酒吧墙壁上写着什么?<br />
<label>
<input type="radio" name="Question7" value="A" />
A.</label>
Love is beautiful<br />
<label><input type="radio" name="Question7" value="B" />
B.</label>
Truth is beautiful<br />
<label><input type="radio" name="Question7" value="C" />
C.</label>
Smile is beautiful</p>
<p>8. 音乐往事中的吧台上摆放着什么?<br />
<label><input type="radio" name="Question8" value="A" />
A.</label>
留声机<br />
<label><input type="radio" name="Question8" value="B" />
B.</label>
收音机<br />
<label><input type="radio" name="Question8" value="C" />
C.</label>
黑胶唱片</p>
<p>9. 音乐往事中男主人公的喜好是?<br />
<label><input type="radio" name="Question9" value="A" />
A.</label>
电影<br />
<label><input type="radio" name="Question9" value="B" />
B.</label>
摄影<br />
<label><input type="radio" name="Question9" value="C" />
C.</label>
烟草和音乐</p>
<p>10.凝固精彩中的主人公爱好什么?<br />
<label><input type="radio" name="Question10" value="A" />
A.</label>
旅游<br />
<label><input type="radio" name="Question10" value="B" />
B.</label>
摄影<br />
<label><input type="radio" name="Question10" value="C" />
C.</label>
上网</p>
<p><br />
<input type="submit" name="Submit" value="提交" />
<br />
</p>
</form>
</body>
</html>
下面是后台代码Test_do.asp,代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file="conn.asp" -->
<!-- #include file="function.asp" -->
<%
Response.CacheControl = "no-cache"
Response.Expires = -1
Response.ExpiresAbsolute=now()-1
if session("username")="" then
Response.Write("<script>alert('请登陆后在进行操作!');window.location='login.asp?reURL=Nv_Scene_Test.asp';</script>")
Response.End()
end if
'定义选项的最高分即总分
Const TOTALSCORE = 100
Const ITEMS = 10
'定义选项分数
Dim Result(9)
'第一题得分标准
Result(0) = "A|10|_|B|0|_|C|0"
'第二题得分标准
Result(1) = "A|0|_|B|10|_|C|0"
'第三题得分标准
Result(2) = "A|10|_|B|0|_|C|0"
'第四题得分标准
Result(3) = "A|0|_|B|0|_|C|10"
'第五题得分标准
Result(4) = "A|0|_|B|0|_|C|10"
'第六题得分标准
Result(5) = "A|10|_|B|0|_|C|0"
'第七题得分标准
Result(6) = "A|0|_|B|10|_|C|0"
'第八题得分标准
Result(7) = "A|10|_|B|0|_|C|0"
'第九题得分标准
Result(8) = "A|0|_|B|0|_|C|10"
'第十题得分标准
Result(9) = "A|0|_|B|10|_|C|0"
''第十一题得分标准
'Result(10) = "A|0|_|B|0|_|C|10"
'
''第十二题得分标准
'Result(11) = "A|0|_|B|10|_|C|0"
'
''第十三题得分标准
'Result(12) = "A|10|_|B|0|_|C|0"
'
''第十四题得分标准
'Result(13) = "A|0|_|B|10|_|C|0"
'
''第十五题得分标准
'Result(14) = "A|0|_|B|0|_|C|10"


If UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" Then
Call Chk_Post()
Dim i,total,selItem,summary,strDes,strOut
total = 0
For i = 0 To (ITEMS-1)
selVal = Trim(Request.Form("Question"&i+1))
arrItem = Split(Result(i),"|_|")
For j = 0 To Ubound(arrItem)
If selVal = Split(arrItem(j),"|")(0) Then
total = total + CInt(Split(arrItem(j),"|")(1))
selItem = selItem &"<li>Question"&i+1&":"&selVal&"</li>"&vbCrLf
End If
Next
Next
summary = FormatPercent(total/TOTALSCORE)
If (total/TOTALSCORE)>=0.6 Then
strDes = "正确率 "&summary&"<br>您已经顺利通过吧"
Else
strDes = "正确率 "&summary&"<br>很遗憾,您正确率还没有达到60%。请再来试试吧!<br><a href=Test.asp'>回在线问答页>></a>"
End If
strOut = "You have Selected these items below:<br>"&selItem&"<br>Total:"&total&"<br>您的正确率为:"&summary
strOut = strOut &"<br>"&strDes
str_sql = "SELECT Count(1) FROM UserInfo WHERE MemberId='"&Session("Id")&"'"
rowCount = DataConn.execute(str_sql)(0)
If rowCount > 0 Then'如果存在就更新个人信息
str_sql = "UPDATE UserInfo "
str_sql = str_sql &" SET Result = '"&FormatNumber(total/TOTALSCORE,2)&"'"
str_sql = str_sql &" ,ip = '"&Get_UserIp()&"'"
str_sql = str_sql &" ,AddTime = getdate()"
str_sql = str_sql &" WHERE MemberID= '"&Session("Id")&"'"
Else
str_sql = "INSERT INTO UserInfo( Result,MemberId,MemberName,ip) "
str_sql = str_sql &" VALUES('"& FormatNumber(total/TOTALSCORE,2)&"','"&Session("Id")&"','"&Session("Username")&"','"&Get_UserIp()&"')"
End If
DataConn.execute(str_sql)
End If

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>在线问答测试结果</title>
<style type="text/css">
<!--
body {
font-size: 12px;
color: #0066FF;
}
input {
border: 1px solid #FFFFFF;
background-color: #EEEEEE;
left: 1px;
top: 1px;
right: 1px;
bottom: 1px;
clip: rect(10px,10px,10px,10px);
margin: 1px;
padding: 1px;
}
-->
</style>
</head>
<body>
<%Response.Write(strOut)%>
</body>
</html><<script type="text/javascript">google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("<s"+"cript type='text/javascript' s"+"rc='http://pagead2.googlesyndication.com/pagead/show_ads"+"."+"js'></scr"+"ipt>");</script>"");
本文介绍了一个使用ASP技术实现的情景问答系统,包括前端页面设计和后端逻辑处理。前端利用HTML和JavaScript确保用户交互体验,后端则采用VBScript进行用户验证及答题评分。
182

被折叠的 条评论
为什么被折叠?



