|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
优点:简单易学、开发速度快、有很多年“历史”,能找到非常多别人做好的程序来用、配合activeX功能强大,很多php做不到的asp+activeX能做到,例如银行安全控件使用ASP+XML架设在线测验体系
<-------------此程序非自己原创-------->
利用这个在线的测验体系,我们能处置任何范例在线测试。只管我们通常为用传统体例完成,读者十分但愿将。
假如从整体上思索。一切成绩都贮存在服务器(它大概在数据库里)内里的的xml文件里。用户筹办消费测验,然后用户测试的通体将经由过程微软的XMLHTTP组件传送到扫瞄器。利用统一个XMLHTTP组件,每当用户哀求一个成绩的时分,那些成绩内容被从服务器注释而且显现在页上。对用户的任何成绩,你所选择的谜底会被贮存在客户端。
一次测验的延续工夫是5分钟。没有回覆不了,你可使用NEXT回覆下洋成绩。一旦用户启动测验,一切成绩目次未来自服务器。所给成绩的Id每哀求到服务器以来在内目次在客户拿给而且给服务器派内贮存。服务器将前往成绩内容,切合成绩Id,从xml文件。当用户选择任何一个谜底时,体系体例将在那些应对内外贮存和在在客户边里的选择内外。用户最初已选择的准确的谜底,应对表用来其实不地反省。选择表在那边是以便体系将主动选择用户已选择了的选择(比方用户点击之前的按钮)测验将停止大概用户点击闭幕按钮大概起首来,工夫(比方5分钟)停止。关于闭幕,体系将盘算其实不右侧谜底的而且展现它。那些以下的文件被在在线的测验体系里利用:
OLExam.html
<html>
<script>
varobjXmlHTTP,objXmlDOM;
varaQuest;//tostorequestionids
varaAnswer=newArray();//totracktheresult
varaSelected=newArray();//tostoreusersresponse
varcount=0;//tostorethecurrentquestionno
varansSel=0;//tostoreusersselection
varExamDuration=5*60;//5minutes
vartimerID;//tostorethesetIntervalfunsid
varradIndex=-1;//tostoretheselectedradiosindex
//constructorlikefunction
//hereXMLobjectsarecreatedand
//Noofquestionsaswellasquestionidslist
//arefetchedfromtheserver.
functioninit(){
objXmlHTTP=newActiveXObject("Microsoft.XMLHTTP");
objXmlDOM=newActiveXObject("Microsoft.XMLDOM");
objXmlHTTP.open("POST","OLExam.asp?Action=Start",false);
objXmlHTTP.send("");
temp=objXmlHTTP.ResponseText;
aQuest=temp.split(",");
//initializetheusersanswerslist
for(i=0;i<aQuest.length;i++){
aAnswer[i]=0;//0forwrong;1forrightanswer
aSelected[i]=-1;//tostoretheradiosindex
}
if(count<aQuest.length){
url="OLExam.asp?Action=NextQ&QNo="+aQuest[count];
objXmlHTTP.open("POST",url,false);
objXmlHTTP.send("");
objXmlDOM.loadXML(objXmlHTTP.ResponseText);
//parsetheresponsecontentfetchedfromtheserver
//anddisplaythequestion
parseQ();
}
//changetheStartbuttonscaptionanditsclickevent
document.frm.btnFinish.value="FinishtheExam";
document.frm.btnFinish.onclick=showResult;//function
//startthetimer
timerID=setInterval("timer()",1000);
}
functiongetPreQ(){
//updatetheusersanswerslist
checkAnswer();
//decrementthequestionno-i.e.topreviousQuestion
count--;
//stopthetimer
clearInterval(timerID);
//fetchthequestionfortheaQuest[count]id
url="OLExam.asp?Action=NextQ&QNo="+aQuest[count];
objXmlHTTP.open("POST",url,false);
objXmlHTTP.send("");
objXmlDOM.loadXML(objXmlHTTP.ResponseText);
//parsetheresponsecontentfetchedfromtheserver
//anddisplaythequestion
parseQ();
//startthetimer
timerID=setInterval("timer()",1000);
}
functiongetNextQ(){
//updatetheusersanswerslist
checkAnswer();
//incrementthequestionno-i.e.tonextQuestion
count++;
//stopthetimer
clearInterval(timerID);
url="OLExam.asp?Action=NextQ&QNo="+aQuest[count];
objXmlHTTP.open("POST",url,false);
objXmlHTTP.send("");
objXmlDOM.loadXML(objXmlHTTP.ResponseText);
//parsetheresponsecontentfetchedfromtheserver
//anddisplaythequestion
parseQ();
//startthetimer
timerID=setInterval("timer()",1000);
}
functionparseQ(){
//fetchthequestionfromtheXMLObject
//formatthedisplay
strOut="<tableborder=0align=centerwidth=80%>";
strOut+="<tr><tdcolspan=2><b>";
strOut+="QuestionNo:"+(count+1)+"of";
strOut+=aQuest.length+"</b></td></tr>";
strOut+="<tr><tdcolspan=2></td></tr>";
temp=objXmlDOM.selectSingleNode("data/qtext").text;
strOut+="<tr><tdcolspan=2><b>"+temp+"</b></td></tr>";
strOut+="<tr><tdcolspan=2></td></tr>";
Nodes=objXmlDOM.selectNodes("data/choice");
for(i=0;i<Nodes.length;i++){
strOut+="<tr><tdalign=centerwidth=10%>";
strOut+="<inputtype=radioname=ansUsr";
strOut+="";
strOut+="value="+(i+1)+"></td><td>";
strOut+=Nodes.item(i).text+"</td></tr>";
}
//setansNo(hiddenfield)totheactualanswer
temp=objXmlDOM.selectSingleNode("data/answer").text;
document.frm.ansNo.value=temp;
strOut+="<tr><tdcolspan=2></td></tr>";
strOut+="<tr><tdcolspan=2>";
if(count!=0){
strOut+="<inputtype=buttonvalue=Previous";
strOut+=">";
}
if(count<aQuest.length-1){
strOut+="<inputtype=buttonvalue=Next";
strOut+=">";
}
strOut+="</td></tr></table>";
//setthestrOutcontentto<P>tagnamedQArea
QArea.innerHTML=strOut;
//setthedefaultvaluetoansSel
ansSel=0;
radIndex=-1;
//checktheradioifuserhasselectedpreviously
if(aSelected[count]!=-1){
radIndex=aSelected[count];
ansSel=radIndex+1;
document.frm.ansUsr[radIndex].checked=true;
}
}
functioncheckAnswer(){
//storetheselectedradiosindex
aSelected[count]=radIndex;
//iftheuserselectionmatchestheactualanswer
if(ansSel==document.frm.ansNo.value)
aAnswer[count]=1;
else
aAnswer[count]=0;
}
functionshowResult(){
rights=0;
//stopthetimer
clearInterval(timerID);
//updatetheusersanswerslist
checkAnswer();
//countnoofanswers
for(i=0;i<aAnswer.length;i++){
if(aAnswer[i]==1)
rights++;
}
strRes="<h2align=center><br>";
//ifalltheanswersarecorrectthengreet
if(rights==aAnswer.length)
strRes+="<br><br>Congratulations...!";
strRes+="<br><br>yourscoreis"+rights;
strRes+="outof"+aAnswer.length+"</h2>";
document.write(strRes);
}
vartimeCount=0;
functiontimer(){
timeCount++;//incrementthetimebyonesecond
//todisplaythetimeinthestatusbar,
//uncommentthenextline
//window.status="..."+timeCount+"secs";
//todisplaythetime
temp="Time:"+parseInt(timeCount/60);
temp+="min:"+(timeCount%60)+"sec";
TBlock.innerText=temp;
//ifthetimeisup
if(timeCount==ExamDuration){
alert("Sorry,timeisup");
showResult();
}
}
</script>
<body>
<h2align=center><fontcolor=green>OnLineExam</font></h2>
<formname=frm>
<tableborder=1width=95%bgcolor=DarkSeaGreenalign=center>
<tr><tdalign=right><bid=TBlock></b></td></tr>
<tr><td>
<pid="QArea">
<center>
<br>
Relax...!Thedurationofthisexamis5minutes.
<br>
Thereisnoordertoansweraquestion.YoumayuseNextas
wellasPreviousbuttontogetaquestiontoanswer.
<br>
<br>
<inputtype=buttonname=btnFinishvalue="StarttheExam"
>
</center>
</p>
<inputtype=hiddenname=ansNo>
</td></tr></table>
</form>
</body>
</html>
OLExam.asp
<%
Response.expires=0
createaninstanceofMSXMLDOMObject
andloadtheQBank.xmlfilewhereallthequestionsare.
setobj=server.createobject("Microsoft.XMLDOM")
obj.async=false
obj.load(Server.MapPath("QBank.xml"))
veryfirstrequestfromtheclient
iftrim(request("Action"))="Start"then
setnoofquestionsperexam
DimNoQ,TotalQ
NoQ=5setnolessthanthetotalquestions
countnoofquestionsinthexmlfile
(orfromdatabase)
TotalQ=obj.selectNodes("data/question").length
DimaQuest(),temp,isExist,strQ
ReDimaQuest(0)tostorethequestionids
generate(=NoQ)questionidsrandomly
whileubound(aQuest)<NoQ
isExist=false
temp=Int((TotalQ*Rnd)+1)
fori=1toubound(aQuest)
ifaQuest(i)=tempthen
isExist=true
exitfor
endif
next
ifNotisExistthen
RedimPreserveaQuest(ubound(aQuest)+1)
aQuest(ubound(aQuest))=temp
strQ=aQuest(i)&","&strQ
endif
wend
removethelastcomma,fromstrQ
strQ=left(strQ,len(strQ)-1)
sendthequestioninthestrQtotheclient
response.writestrQ
allfurtherrequests-afterthefirstrequest
elseiftrim(request("Action"))="NextQ"then
fetchthequestionfromtheXMLObject
andformtheoutputstring
temp="data/question[@id="&trim(request("QNo"))&"]"
setNode=obj.selectSingleNode(temp)
strXML="<data>"
strXML=strXML&"<qtext>"
strXML=strXML&Node.selectSingleNode("qtext").text
strXML=strXML&"</qtext>"
strXML=strXML&"<answer>"
strXML=strXML&Node.selectSingleNode("answer").text
strXML=strXML&"</answer>"
setNode=Node.selectNodes("choices/choice")
fori=0toNode.length-1
strXML=strXML&"<choice>"
strXML=strXML&Node.item(i).text
strXML=strXML&"</choice>"
next
strXML=strXML&"</data>"
sendtheoutputtotheclient
Response.Write(strXML)
endif
%>
QBank.xml
<?xmlversion="1.0"?>
<data>
<questionid="1">
<qtext>WhatdoesKBstandfor?</qtext>
<choices>
<choice>KiloBits</choice>
<choice>KeyBoard</choice>
<choice>KiloBytes</choice>
<choice>None</choice>
</choices>
<answer>3</answer>
</question>
<questionid="2">
<qtext>CPUstandsfor</qtext>
<choices>
<choice>CentralProcessingUnit</choice>
<choice>CentralPowerUnit</choice>
<choice>CoreProcessingUnit</choice>
<choice>CorePowerUnit</choice>
</choices>
<answer>1</answer>
</question>
<questionid="3">
<qtext>1KBequals</qtext>
<choices>
<choice>1000Bytes</choice>
<choice>1024Bytes</choice>
<choice>1000Bits</choice>
<choice>1024Bits</choice>
<choice>Nothing</choice>
</choices>
<answer>2</answer>
</question>
<questionid="4">
<qtext>RAMis</qtext>
<choices>
<choice>RandomAccessModifier</choice>
<choice>PrimaryMemory</choice>
<choice>SecondaryMemory</choice>
<choice>ReadAndModify</choice>
</choices>
<answer>2</answer>
</question>
<questionid="5">
<qtext>HardDiskis</qtext>
<choices>
<choice>Hardtobreak</choice>
<choice>PrimaryMemoryStorage</choice>
<choice>TemporaryMemoryStorage</choice>
<choice>SecondaryMemoryStorage</choice>
</choices>
<answer>4</answer>
</question>
<questionid="6">
<qtext>ComputerMonitorisused</qtext>
<choices>
<choice>Tomonitoractivities</choice>
<choice>TocontrolComputer</choice>
<choice>Asdisplayunit</choice>
<choice>None</choice>
</choices>
<answer>3</answer>
</question>
<questionid="7">
<qtext>XMLstandsfor</qtext>
<choices>
<choice>ExtendedMarkupLanguage</choice>
<choice>ExtendedModelLanguage</choice>
<choice>ExtensibleMarkupLanguage</choice>
<choice>ExtensibleModelLanguage</choice>
</choices>
<answer>3</answer>
</question>
<questionid="8">
<qtext>ASPstandsfor</qtext>
<choices>
<choice>ActiveServerPage</choice>
<choice>ApplicationServiceProvision</choice>
<choice>AsSoonasPossible</choice>
<choice>All</choice>
</choices>
<answer>1</answer>
</question>
</data>
写软件都是想的时间比写的时间要长的.如果反过来了就得看看是什么原因了.另外大家可以回去问问公司里的小MM.(一般企业里,跟你们交付软件接触得最多的是她们) |
|