ASP在線問答的實例代碼_ASP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:ASP利用XML打包指定文件夾 并上傳到WEB目錄中,自行解包'======================== '文件1 'Pack.asp '更改 Cpathname 這一變量 '將在當前目錄生成一個DATA.XML文件 '將DATA.XML及文件2(install.asp)上傳至WEB根目錄 '運行install.asp解包 '手動刪除以上兩個文件 '======================== % Option Explic
ASP在線問答的實例代碼首先,是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
- totaltotal = total + CInt(Split(arrItem(j),"|")(1))
- selItemselItem = 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
- strOutstrOut = 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_sqlstr_sql = str_sql &" SET Result = '"&FormatNumber(total/TOTALSCORE,2)&"'"
- str_sqlstr_sql = str_sql &" ,ip = '"&Get_UserIp()&"'"
- str_sqlstr_sql = str_sql &" ,AddTime = getdate()"
- str_sqlstr_sql = str_sql &" WHERE MemberID= '"&Session("Id")&"'"
- Else
- str_sql = "INSERT INTO UserInfo( Result,MemberId,MemberName,ip) "
- str_sqlstr_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>
分享:ASP Error對象的技巧在VBScript中,有一個On Error Resume Next語句,它使腳本解釋器忽略運行期錯誤并繼續腳本代碼的執行。接著該腳本可以檢查Err.Number屬性的值,判別是否出現了錯誤。如果出現錯誤,返回一個非零值。在ASP 3.0中,也可以使用On Error Goto 0“轉回到”缺省的
相關ASP教程:
- 相關鏈接:
- 教程說明:
ASP教程-ASP在線問答的實例代碼
。