其中 填空题的 空 使用[q][/q]
\[q\].*?\[\/q\]匹配的
examine.htm
<!--{if empty($_TPL['getmore'])}-->
<!--{eval $_TPL['titles'] = array('首页');}-->
<!--{template header_exam}-->
<script language="JavaScript" type="text/javascript" src="source/jquery-1.3.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="source/jquery-ui-1.7.1.custom.min.js"></script>
<script language="JavaScript" type="text/javascript" src="source/public.js"></script>
<script language="JavaScript" type="text/javascript" src="source/script_exam.js"></script>
<div id="dialog-confirm" title="您确定要继续提交?"></div>
<div id="dialog-exit" title="您确定要放弃考试?">是否要放弃考试,如果现在放弃,将不记录考试成绩,并且考试次数将减少一次!</div>
<div id="dialog-time" title="限制时间内不能提交考试"></div>
<div id="dialog-goto" title="非法行为!">检测到您有非法退出的行为!</div>
<!--{if $_GET['op'] == 'examine'}-->
<div id="wrap">
<!--{if empty($_TPL['nosidebar'])}-->
<div id="main">
<div class="side">
<div class="block style1" style="min-height:520px;background:#DDEFFB;">
<h2>题目序列</h2>
说明:试题序号的底色为白色时表示该题未答,为蓝色时表示该题已答。
<hr>
<ul class="folder" style="width:102px;" id="tsn">
</ul>
</div>
</div>
<div id="mainarea">
<!--{if $_SGLOBAL['ad']['contenttop']}--><div id="ad_contenttop"><!--{ad/contenttop}--></div><!--{/if}-->
<!--{/if}-->
<!--{/if}-->
<span id="pid" style="display:none;">{$paid}</span>
<span id="pf" style="display:none;">{$_SCONFIG['postafter']}</span>
<div id="content" style="width:800px;">
<div class="feed" >
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="460" height="22" colspan="2"><strong>考试科目:<span style="color:red;">$partname</span></strong></td>
<td rowspan="3" align="center">考试剩余时间:<span id="lasttime" style="color:red;font-size:14px;font-weight:bold;"></span><br><br><a href="#" onclick="return exam_exit();" style="text-decoration:underline;">放弃考试</a> <img src="/image/btn_jj.gif" onclick="return submittest();" style="cursor:pointer;"></td>
</tr>
<tr>
<td width="460" height="22" colspan="2"><div id="jdt">考试进度:<span id="exam_progress" ></span></div></td>
</tr>
<tr>
<td height="22" colspan="2">已答试题:<span id="qt" style="color:red;"></span> 未答试题:<span id="qf" style="color:red;"></span> </td>
<td align="center"></td>
</tr>
</table>
</div>
<div id="q_content" style="border:1px solid #eeeeee;padding:10px;display:inline-block;">
<div id="q_sn"> </div>
<div id="q_title" style="margin-left:50px;"></div>
<div id="select_answer" style="margin-left:50px;"></div>
<div id="my_answer" style="margin-left:50px;"></div>
<div>
<form name="exam" action="space.php?do=exam&op=exam_submit" method="POST" >
<textarea name="quest" id="last_answer" style="width:480px;height:200px;display:none;" ></textarea>
</form>
</div>
<hr style="border:1px solid #eeeeee;">
<table style="margin-left:50px;"><tr><td id="goto_page"></td></tr></table>
<!-- <div id="goto_page" style="display:inline-block;margin-left:50px;width:60%;border:1px solid green;"></div>-->
</div>
</div>
<!--{/if}-->
<script language="JavaScript" type="text/javascript">
var pid = $("#pid").html();
get_paper(pid);
$(function(){
$("#dialog-confirm").dialog({
autoOpen:false,
resizable: false,
width:200,
height:140,
modal: true,
buttons: {
继续答题: function() {
$(this).dialog('close');
return false;
},
确认交卷: function() {
window.onbeforeunload = null;
submital();
$(this).dialog('close');
}
}
});
$("#dialog-exit").dialog({
autoOpen:false,
resizable: false,
width:320,
height:150,
modal: true,
buttons: {
取消: function() {
$(this).dialog('close');
return false;
},
确定: function() {
unclose();
window.location = "space.php";
$(this).dialog('close');
}
}
});
$("#dialog-time").dialog({
autoOpen:false,
resizable: false,
width:320,
height:150,
modal: true,
buttons: {
确定: function() {
$(this).dialog('close');
}
}
});
$("#dialog-goto").dialog({
autoOpen:false,
resizable: false,
width:320,
height:150,
modal: true,
buttons: {
继续考试: function() {
$(this).dialog('close');
}
}
});
make_pic();
});
</script>
<!--{/if}-->
<!--{template footer}-->
lms = "";
rms = 0;
pms = "";
qtinfo = {"1":"单选题","2":"多选题","3":"判断题","4":"填空题","5":"简答题","6":"论述题"};
quest = "";
qtv = "";
qfv = "";
MyUtil={};
function obj2str(o){
var r = [];
if(typeof o =="string") return "\""+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
if(typeof o =="undefined") return "";
if(typeof o == "object"){
if(o===null) return "null";
else if(!o.sort){
for(var i in o)
r.push('"'+i+"\":"+obj2str(o[i]))
r="{"+r.join()+"}"
}else{
for(var i =0;i<o.length;i++)
r.push(obj2str(o[i]))
r="["+r.join()+"]"
}
return r;
}
return o.toString();
}
//考试初始化
function get_paper(pid){
$.get("student!examine.do",{"ajax":"yes","paperid":1,"rad":Math.random()},function(data){
if(data == 'nodata'){
alert('暂时没有试卷!');
window.location = "space.php";
return false;
}
//alert(unescape(data.replace(/\\u/g,'%u')));
data = eval('('+unescape(data.replace(/\\u/g,'%u'))+')');
//alert(data.paper.prompt);
lms = data.paper.totaltime;
pms = data.paper.postafter;
quest = data.question;
make_sntree(quest); //生成序列树
goto_topic(quest[0]['questionorder']); //生成第一道题
update_already(0,quest.length); //更新已做未做
setInterval("set_last_time()",1000); //设置倒计时
});
}
//传入时间戳,显示倒计时
function get_last_time(ms){
var s = ms % 60; //得到剩余秒
var m = (ms-s) / 60; //得到剩余分
s = s + '';
s = (s.length == 1) ? '0'+s : s ;
return {"m":m,"s":s}
}
//更新倒计时
function set_last_time(){
lms--;
if(lms == 0){
submital();
}
rms++;
ems = get_last_time(lms);
$("#lasttime").html(ems.m+"分"+ems.s+"秒");
}
//生成序列树
function make_sntree(quest){
if(quest == undefined){
alert("没有获取到考题!");
return false;
}
for(i=0;i<quest.length;i++){
var qsn = quest[i].questionorder; //得到题序号(qsn)
var qid = quest[i].qid; //得到题号(qid)
var qtype = quest[i].type; //题型标识(qtype)
var qtypeinfo = qtinfo[quest[i].type]; //题型说明(qtypeinfo)
if(!$("#qt_"+qtype).html() && !$("#tn_"+qtype).html()){
$("#tsn").append('<li class="active" id="qt_'+qtype+'"><a>'+qtypeinfo+'</a><div id="tn_'+qtype+'"><a class="qe1" id="sn_'+qsn+'" onclick="goto_topic('+qsn+');">'+qsn+'</a></div></li><br><br>');
}else{
$("#tn_"+qtype).append('<a class="qe1" id="sn_'+qsn+'" onclick="goto_topic('+qsn+');">'+qsn+'</a>');
}
}
}
//更新已做未做
function update_already(qt,qf){
if(qt == undefined && qf == undefined){
var r=0;
var c=quest.length;
for(i=0;i<c;i++){
if(quest[i].isalready == '1'){
r++;
}
}
qtv = r;
qfv = c-r;
}else{
qtv = qt;
qfv = qf;
}
$("#qt").html(qtv);
$("#qf").html(qfv);
}
//根据题ID生成并跳到题目
function goto_topic(qsn){
var qid = quest[qsn-1]['qid'];
var qtype = quest[qsn-1]['type'];
var qinfo = qtinfo[qtype];
var score = quest[qsn-1]['questionscore'];
var sa = "";
var qcount = quest.length;
var psn = parseInt(qsn)-1;
var nsn = parseInt(qsn)+1;
var ranswer = quest[psn]['rightanswer'];
var re = /\[q\].*?\[\/q\]/g;
$("#my_answer").hide();
$.get("student!question.do",{"ajax":"yes","qid":qid,"rad":Math.random()},function(data){
if(data == 'noquest'){
alert('没有找到考题!');
return false;
}
data = eval('('+unescape(data.replace(/\\u/g,"%u"))+')');
var ds = data.selectanswer;
var title = re.test(data.title) ? data.title.replace(re,' <input type="text" size="4" style="border:1px solid #eeeeee;" onblur="set_answer('+qsn+',document.getElementById(\'q_title\'),\''+qtype+'\')"> ') : data.title ;
//alert(title);
var ret1 = /(<p><span.*?>)\d+[\..\,,。、](.*?)(<\/span>)<\/p>/;
var ret2 = /(<p>)\d+[\..\,,。、](.*?)<\/p>/;
var ret3 = /^(\d+[\..\,,。、])(.*?)/;
if(ret1.test(title)){
title = title.replace(ret1,"$1$2$3");
}
if(ret2.test(title)){
title = title.replace(ret2,"$1$2$3");
}
if(ret3.test(title)){
title = title.replace(ret3,"$2");
}
if(isinarr(new Array('1','2','3'),qtype)){
title += '<span id="input_answer" style="font-weight:bold;color:green;">['+quest[parseInt(qsn)-1]['studentanswer']+']</span>';
}
$("#q_sn").html('第'+qsn+'题 ('+qinfo+')');
$("#q_title").html(title);
$("#q_title").html(title+' ('+score+'分)');
if(qsn == '1'){
$("#goto_page").html(' <img src="image/nq.gif" onclick="goto_topic(\''+nsn+'\');" style="cursor:pointer;"> ');
}else if(qsn == qcount){
$("#goto_page").html(' <img src="image/pq.gif" onclick="goto_topic(\''+psn+'\');" style="cursor:pointer;">');
}else{
$("#goto_page").html(' <img src="image/pq.gif" onclick="goto_topic(\''+psn+'\');" style="cursor:pointer;"> <img src="image/nq.gif" onclick="goto_topic(\''+nsn+'\');" style="cursor:pointer;">');
}
switch(qtype){
case "1":
case "3":
for(i=0;i<ds.length;i++){
k = ds[i].substr(0,1);
sed = k == quest[qsn-1]['studentanswer'] ? "checked" : "" ;
sa += '<input type="radio" name="an_'+qid+'" value="'+k+'" onclick="set_answer('+qsn+',this,\''+qtype+'\')" '+sed+' > '+ds[i]+'<br><br>';
}
break;
case "2":
for(i=0;i<ds.length;i++){
k = ds[i].substr(0,1);
sed = (quest[qsn-1]['studentanswer'].indexOf(k) < 0) ? "" : "checked" ;
sa += '<input type="checkbox" name="an_'+qid+'" value="'+k+'" onclick="set_answer('+qsn+',this,\''+qtype+'\')" '+sed+' > '+ds[i]+'<br><br>';
}
break;
case "5":
case "6":
$("#my_answer").show();
val = quest[qsn-1]['studentanswer'].length ? quest[qsn-1]['studentanswer'] : "";
$("#my_answer").html('<textarea style="width:480px;height:200px;" onblur="set_answer('+qsn+',this,\''+qtype+'\')">'+val+'</textarea>');
break;
}
$("#select_answer").html(sa);
});
document.documentElement.scrollTop=0;
}
//答题方法
function set_answer(qsn,obj,qtype){
//将答案更新到全局变量里
switch(qtype){
case "1":
case "3":
case "5":
case "6":
quest[parseInt(qsn)-1]['studentanswer'] = $.trim(obj.value);
break;
case "2":
if(obj.checked){
var anw = quest[parseInt(qsn)-1]['studentanswer'].indexOf(obj.value) < 0 ? obj.value : "" ;
quest[parseInt(qsn)-1]['studentanswer'] += anw;
quest[parseInt(qsn)-1]['studentanswer'] = str_sort(quest[parseInt(qsn)-1]['studentanswer']);
}else{
quest[parseInt(qsn)-1]['studentanswer'] = quest[parseInt(qsn)-1]['studentanswer'].replace(obj.value,"");
}
break;
case "4":
var anobj = $("#"+obj.id+" input");
var anarr = new Array();
for(i=0;i<anobj.length;i++){
anarr.push(anobj[i].value);
}
quest[parseInt(qsn)-1]['studentanswer'] = anarr;
break;
}
if(isinarr(new Array('1','2','3'),qtype)){
var anreg = /(<span\s+.*?id=input_answer.*?>\[).*?(\]<\/span>)/i;
//alert(navigator.userAgent);
if(navigator.userAgent.indexOf("MSIE") > 1){
anreg = /(<span\s+.*?id=input_answer.*?>\[).*?(\]<\/span>)/i;
}else if(navigator.userAgent.indexOf("AppleWebKit") >1){
anreg = /(<span\s+.*?id=\"input_answer\".*?>\[).*?(\]<\/span>)/i;
}else if(navigator.userAgent.indexOf("Firefox") > 1){
anreg = /(<span\s+.*?id=\"input_answer\".*?>\[).*?(\]<\/span>)/i;
}
var qhtml = $("#q_title").html();
$("#q_title").html(qhtml.replace(anreg,"$1"+quest[parseInt(qsn)-1]['studentanswer']+"$2"));
}
quest[parseInt(qsn)-1]['isalready'] = '1'; //设置为已答
//更新到服务器,未做。。。
update_already();
set_progress();
$("#sn_"+qsn).attr("class","qe2");
}
//交卷方法
function submital(){
// qdata = new Array();
// for(i=0;i<quest.length;i++){
// qdata[i] = new Object();
// qdata[i].questionorder = quest[i].questionorder;
// qdata[i].studentanswer = quest[i].studentanswer;
// qdata[i].isalready = quest[i].isalready;
//
//
//
//
//
// }
qdata = obj2str(quest);
//$("#last_answer").show();
$("#last_answer").html(qdata);
if(window.onbeforeunload = null){
document.exam.submit();
}
document.exam.submit();
}
加入错题本:
//function intoError(sid,spid,pid,qid){
// $.get("space.php",{"do":"ajax","op":"infoError","sid":sid,"spid":spid,"paperid":pid,"qid":qid,"rad":Math.random()},function(data){
// if(data == 'exist'){
// alert('该题早已加入错题本!');
// }else if(data == 'full'){
// alert('错题本已满,不能加入!');
// }else if(data == 'ok'){
// alert('加入错题本成功!');
// $("#err_"+qid).html('<img src="image/btn_exist.gif" border="0">');
// //$("#err_"+qid).css("color","#228B22");
// }else if(data == 'no'){
// alert('加入错题本失败!');
// }
// });
//}
//更新到服务器缓存
//function update_cache(qsn,qan){
//
// qdata = new Array();
//
// for(i=0;i<quest.length;i++){
// qdata[i] = new Object();
// qdata[i].questionorder = quest[i].questionorder;
// qdata[i].studentanswer = quest[i].studentanswer;
// qdata[i].isalready = quest[i].isalready;
// }
//
// qdata = obj2str(qdata);
//
// $.post("space.php?do=ajax",{"op":"update_exam_cache","qdata":qdata,"rad":Math.random()},function(data){
// if(data != "ok"){
// alert("更新答题到服务器失败!");
// return false;
// }
// });
//}
//操作试题分析
function analyse(qsn){
$(".an_"+qsn).toggle();
$("#anal_"+qsn).html().indexOf("打开") >= 0 ? $("#anal_"+qsn).html("关闭试题解析") : $("#anal_"+qsn).html("打开试题解析") ;
}
//放弃考试提示
function exam_exit(){
$("#dialog-exit").dialog("open");
return false;
}
//交卷前的提示程序
function submittest(){
var pfv = parseInt($("#pf").html());
if(rms < pfv){
$("#dialog-time").html("考试时间不足"+pfv+"秒,不能交卷!");
$("#dialog-time").dialog("open");
}else{
var qf = parseInt($("#qf").html());
if(qf>0 && parseInt(lms)){
$("#dialog-confirm").html("您还有"+qf+"道试题未做,是否继续交卷!");
$("#dialog-confirm").dialog("open");
}else{
return submital();
}
}
}
//生成空进度条
function make_pic(){
var mpic = "";
for(i=1;i<=20;i++){
mpic += '<img class="epg" id="pg_'+i+'" src="image/jd_gray.gif" >';
}
$("#exam_progress").html(mpic);
}
//设置进度条进度
function set_progress(){
var qt = parseInt($("#qt").html()); //得到已做题数
var qf = parseInt($("#qf").html()); //得到未做题数
var qc = qt+qf; //得到总共题数
var pv = Math.round(20 * (qt / qc)); //得到进度值
$(".epg").attr("src","image/jd_gray.gif");
for(i=1;i<=pv;i++){
$("#pg_"+i).attr("src","image/jd_blue.gif");
}
}
//是否交卷
function issubmit(){
if(!confirm("所有考题已做完,是否立即交卷?")){
return false;
}else{
submital();
}
}
function test(){
var obj = document.getElementById("dialog-confirm").style;
$.each(obj,function(i,n){
alert(i+','+n);
});
}
Action
private String quest;
getter setter
传进来的json
{"paper":
{"endtime":"","sid":"112",
"pass_score":"60",
"starttime":"1314092189",
"laststate":"",
"total_score":"100",
"already_nums":"",
"ispass":"0",
"marktype":"0",
"question_nums":"130",
"examtype":"1",
"get_score":"",
"partid":"12",
"postafter":"60",
"prompt":{"90":"高 手 啊","70":"恭 喜 获 得 高 分","80":"太 厉 害 了","60":"恭 喜 及 格","100":"无 敌 了"},
"totaltime":"7200",
"paperid":"23",
"subjectivetype":"0",
"residual_nums":""},
"question":[
{
"selectanswer":["A:答案A","B:答案B","C:答案C","D:答案D"],
"rightanswer":"中国人民银行开始行使直接审批金融机构的职能",
"studentanswer":"",
"qid":3,
"marktype":"1",
"type":1,
"isright":"0",
"info":"",
"qtypeinfo":"单 选 题",
"title":"就监督管理部分而言,第十届全国人民代表大会常务委员会第六次会议通过的《中国人民银行法修正案》修订的重点是?",
"questionorder":1,
"isalready":"0",
"questionscore":10,
"studentscore":""
}]
}
传出的json
[{"selectanswer":["A:id=1选项A","B:选项B","C:选项C","D:选项D"],
"rightanswer":"question_id为一的题",
"studentanswer":"A",
"qid":1,
"marktype":"1",
"type":"1",
"isright":"0",
"info":"",
"qtypeinfo":"单 选 题",
"title":"question_id为一的题",
"questionorder":1,
"isalready":"1",
"questionscore":10,
"studentscore":""},
{"selectanswer":["A:选项A","B:选项B","C:选项C","D:选项D"],
"rightanswer":"中国人民银行开始行使直接审批金融机构的职能",
"studentanswer":"A",
"qid":3,
"marktype":"1",
"type":"1",
"isright":"0",
"info":"",
"qtypeinfo":"单 选 题",
"title":"就监督管理部分而言,第十届全国人民代表大会常务委员会第六次会议通过的《中国人民银行法修正案》修订的重点是?",
"questionorder":2,
"isalready":"1",
"questionscore":10,
"studentscore":""
}]