asp比较灵活的在线问答的示例

<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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值