求助:ASP多选题判分问题(无法正常判分)

来源:百度知道 编辑:UC知道 时间:2024/05/30 14:12:09
试题生成代码
<%
dim d,e,f
'产生一个随机数d:
randomize
d=int(rnd()*6)+1
'记录指针向下移动d条:
rs2.move d
e=1
'利用循环随机抽取3道题目并逐一显示
while not rs2.eof and e<=3
'输出题号及题目:
response.Write "<b>"&e&"."&rs2(1)&"</b>"
response.Write "<blockquote>"
'生成4个单选按钮并输出对应选项内容:
for f=1 to 4
response.write "<input type=checkbox name=no2"&e&" value="&f&">"
response.Write ""&rs2("选项"&f)&"<br>"
next
response.Write "</blockquote>"
'用隐含模式传送当前答案
ans2 = "<input type=hidden name=Da2"&e&" value="&rs2(6)&">"
response.Write ans2
d=int(rnd()*6)+1
rs2.move d
e=e+1
wend
rs2.close
set conn=nothing
%>

判分相关代码
<%
dim score2,sele2,ans2,strl2
score2=0
for f=1 to 3<

如此修改:

if Trim(ans2)=Trim(sele2) then
score2=score2+10
end if

如果回答及答案的是字符型数据,如:a,b,c,d
则采用以下方式更可靠:

if UCase(Trim(ans2))=UCase(Trim(sele2)) then
score2=score2+10
end if
====================================
修改如下(将所有的空格都去掉后进行比较):
if replace(ans2," ","")=replace(sele2," ","") then
score2=score2+10
end if

request.Form("no2"&f) 取提交页的变量为什么会是,"no"&f,不是no2 吗

分数无法判断,就是if ans2=sele2 then 这句条件判断出了问题,要判断两个答案是否相同,首先两个比较的数据要是相同的类型,应该用Ucase(trim(变量)).
也就是在改sele2=Ucase(trim(request.Form("no2")))
ans2=Ucase(trim(request.Form("da2")))

你可以用 Trim(变量名)去掉变量前后的空格

如果只是有空格的话,用trim()去掉空格