ASP在線問答的實(shí)例代碼_ASP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:ASP利用XML打包指定文件夾 并上傳到WEB目錄中,自行解包'======================== '文件1 'Pack.asp '更改 Cpathname 這一變量 '將在當(dāng)前目錄生成一個(gè)DATA.XML文件 '將DATA.XML及文件2(install.asp)上傳至WEB根目錄 '運(yùn)行install.asp解包 '手動(dòng)刪除以上兩個(gè)文件 '======================== % Option Explic
ASP在線問答的實(shí)例代碼首先,是HTML文件,為Test.asp,代碼如下:
- <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
- <%
- if session("username")="" then
- Response.Write("<script>alert('請(qǐng)登陸后在進(jìn)行操作!');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("請(qǐng)選擇第"+i+"題答案");
- return false;
- }
- }
- if(!flag)
- {
- alert("請(qǐng)選擇第"+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>
- 海邊的風(fēng)景<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>
- 蔚藍(lán)海岸</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. 音樂往事中的吧臺(tái)上擺放著什么?<br />
- <label><input type="radio" name="Question8" value="A" />
- A.</label>
- 留聲機(jī)<br />
- <label><input type="radio" name="Question8" value="B" />
- B.</label>
- 收音機(jī)<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>
- 上網(wǎng)</p>
- <p><br />
- <input type="submit" name="Submit" value="提交" />
- <br />
- </p>
- </form>
- </body>
- </html>
下面是后臺(tái)代碼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('請(qǐng)登陸后在進(jìn)行操作!');window.location='login.asp?reURL=Nv_Scene_Test.asp';</script>")
- Response.End()
- end if
- '定義選項(xiàng)的最高分即總分
- Const TOTALSCORE = 100
- Const ITEMS = 10
- '定義選項(xiàng)分?jǐn)?shù)
- Dim Result(9)
- '第一題得分標(biāo)準(zhǔn)
- Result(0) = "A|10|_|B|0|_|C|0"
- '第二題得分標(biāo)準(zhǔn)
- Result(1) = "A|0|_|B|10|_|C|0"
- '第三題得分標(biāo)準(zhǔn)
- Result(2) = "A|10|_|B|0|_|C|0"
- '第四題得分標(biāo)準(zhǔn)
- Result(3) = "A|0|_|B|0|_|C|10"
- '第五題得分標(biāo)準(zhǔn)
- Result(4) = "A|0|_|B|0|_|C|10"
- '第六題得分標(biāo)準(zhǔn)
- Result(5) = "A|10|_|B|0|_|C|0"
- '第七題得分標(biāo)準(zhǔn)
- Result(6) = "A|0|_|B|10|_|C|0"
- '第八題得分標(biāo)準(zhǔn)
- Result(7) = "A|10|_|B|0|_|C|0"
- '第九題得分標(biāo)準(zhǔn)
- Result(8) = "A|0|_|B|0|_|C|10"
- '第十題得分標(biāo)準(zhǔn)
- Result(9) = "A|0|_|B|10|_|C|0"
- ''第十一題得分標(biāo)準(zhǔn)
- 'Result(10) = "A|0|_|B|0|_|C|10"
- '
- ''第十二題得分標(biāo)準(zhǔn)
- 'Result(11) = "A|0|_|B|10|_|C|0"
- '
- ''第十三題得分標(biāo)準(zhǔn)
- 'Result(12) = "A|10|_|B|0|_|C|0"
- '
- ''第十四題得分標(biāo)準(zhǔn)
- 'Result(13) = "A|0|_|B|10|_|C|0"
- '
- ''第十五題得分標(biāo)準(zhǔn)
- '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>您已經(jīng)順利通過吧"
- Else
- strDes = "正確率 "&summary&"<br>很遺憾,您正確率還沒有達(dá)到60%。請(qǐng)?jiān)賮碓囋嚢桑?/span><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'如果存在就更新個(gè)人信息
- 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>在線問答測(cè)試結(jié)果</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對(duì)象的技巧在VBScript中,有一個(gè)On Error Resume Next語句,它使腳本解釋器忽略運(yùn)行期錯(cuò)誤并繼續(xù)腳本代碼的執(zhí)行。接著該腳本可以檢查Err.Number屬性的值,判別是否出現(xiàn)了錯(cuò)誤。如果出現(xiàn)錯(cuò)誤,返回一個(gè)非零值。在ASP 3.0中,也可以使用On Error Goto 0“轉(zhuǎn)回到”缺省的
相關(guān)ASP教程:
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無組件分頁實(shí)現(xiàn)思路及代碼
ASP教程Rss訂閱編程教程搜索
ASP教程推薦
- asp連接SQL和Access數(shù)據(jù)代碼(asp里的隨機(jī)函數(shù))
- 如何防止頁面中的敏感信息被提取
- 怎樣獲得剛插入數(shù)據(jù)庫(kù)的記錄的ID號(hào)?
- ASP教程:自己寫的數(shù)據(jù)庫(kù)操作類
- ASP教程:一個(gè)簡(jiǎn)單的AJAX例子
- ASP 編程中20個(gè)非常有用的例子(二)
- ASP中set與dim的區(qū)別(自己的理解)
- ASP操作XML文件的主要方法和實(shí)現(xiàn)
- ASP長(zhǎng)數(shù)字用逗號(hào)隔開顯示實(shí)例代碼
- 如何用asp程序處理數(shù)據(jù)庫(kù)被掛馬的問題
- 相關(guān)鏈接:
- 教程說明:
ASP教程-ASP在線問答的實(shí)例代碼
。