怎么在控制台执行函数
本帖最后由 xfzsun 于 2022-3-2 19:51 编辑麻烦大家提供个思路,怎么在控制台执行getuseranswer()函数并返回结果,谢谢
<!-- lpstart-->
<div id="score_ladyout" class="easyui-layout" style="width:100%;height:100%;">
<div region="center"style="padding:5px;">
<div style="width:100%;height:100%;">
<table id="score_exam" style="width:85%;margin:0 auto;word-break:break-all;">
<tr style="text-align: center;"><td id="score_name"></td></tr>
<tr><td id="score_description"></td></tr>
<tr><td style="border-bottom: dashed 1px black;"></td></tr>
</table>
</div>
</div>
<div region="east" split="true"style="width:300px;" title="考试信息统计">
<div id="useranwser_info">
</div>
</div>
<!-- lpend -->
<script type="text/javascript">
var IndexTips=new Array("一","二","三","四");
$(function() {
$.ajax({
url: 'action/exam/getexamquestion.do',
success: function(data) {
$('#score_name').html("<h2>"+data.examname+"</h2>");
/* $("#infoexamname").text(data.examname);
$("#infoexamstime").text(dateformat(examstartime.getTime())); */
$('#score_description').html("<font color='red'>考试说明:" + data.examdescription+"</font>");
//选择题
var questionhtml="";
var questIndex=0;
if(data.options!=undefined&&data.options.length!=0){
$('#score_exam').append("<tr><td><h4>"+IndexTips+".单选题</h4></td></tr>");
IndexTips.shift();
questionhtml="";
$.each(data.options,function(index,item){
questionhtml+="<tr><td id=\""+item.questionid+"\"><b>"+(++questIndex)+"."+item.question+"</b></td></tr>";
if(item.options!=null){
questionhtml+="<tr><td>";
$.each(item.options,function(opindex,opitem){
questionhtml +="<p style='text-indent:2em;'>" +opitem.options + ".<input type='radio' name=radio_"+opitem.questionid+" value="+opitem.options+" id=\"radio_"+opitem.questionid+"_"+opitem.options+"\" />" +opitem.optiontext + "</p>";
});
questionhtml+="</td></tr>";
}
});
$('#score_exam').append(questionhtml);
}
//多选题
if(data.mulits!=undefined&&data.mulits.length!=0){
$('#score_exam').append("<tr><td><h4>"+IndexTips+".多选题</h4></td></tr>");
IndexTips.shift();
questionhtml="";
$.each(data.mulits,function(index,item){
questionhtml+="<tr><td id=\""+item.questionid+"\"><b>"+(++questIndex)+"."+item.question+"</b></td></tr>";
if(item.options!=null){
questionhtml+="<tr><td>";
$.each(item.options,function(opindex,opitem){
questionhtml +="<p style='text-indent:2em;'>" +opitem.options + ".<input type='checkbox' name=\"mulit_"+opitem.questionid+"\" value=\""+opitem.options+"\"id=\"mulit_"+opitem.questionid+"_"+opitem.options+"\" />" +opitem.optiontext + "</label></p>";
});
questionhtml+="</td></tr>";
}
});
$('#score_exam').append(questionhtml);
}
//判断题
if(data.judges!=undefined&&data.judges.length!=0){
$('#score_exam').append("<tr><td><h4>"+IndexTips+".判断题</h4></td></tr>");
IndexTips.shift();
questionhtml="";
$.each(data.judges,function(index,item){
questionhtml+="<tr><td id=\""+item.questionid+"\"><b>"+(++questIndex)+"."+item.question+"</b></td></tr>";
if(item.options!=null){
questionhtml+="<tr><td>";
$.each(item.options,function(opindex,opitem){
questionhtml +="<p style='text-indent:2em;'>" +opitem.options + ".<input type='radio' name=judge_"+opitem.questionid+" value="+opitem.options+"id=\"judge_"+opitem.questionid+"_"+opitem.options+"\"/>" +opitem.optiontext + "</p>";
});
questionhtml+="</td></tr>";
}
});
$('#score_exam').append(questionhtml);
}
//论述题
if(data.essays!=undefined&&data.essays.length!=0){
$('#score_exam').append("<tr><td><h4>"+IndexTips+".论述题</h4></td></tr>");
IndexTips.shift();
questionhtml="";
$.each(data.essays,function(index,item){
questionhtml+="<tr><td id=\""+item.questionid+"\"><b>"+(++questIndex)+"."+item.question+"</b></td></tr>";
questionhtml+="<tr><td><textarea id=textarea_"+item.questionid+" name=textarea_"+item.questionid+" style='width:calc(100% - 100px);height:80px;' ></textarea></td></tr>";
});
$('#score_exam').append(questionhtml);
}
getuseranswer();
},
error: function() {
showMessage("获取考题失败!");
},
data: {
'examid': 'null',
'taskid':'null'
},
type: 'post',
dataType: 'json'
});
});
function getuseranswer(){
$.ajax({
url:'action/exam/getuseranswer.do',
success:function(data){
if(data.answer!=null){
$.each(data.answer,function(index,item){
var questioninfo=item.questionid.split("_");
if(item.score==0)
$("#"+questioninfo).css("background-color","#FFB5B5");
if(questioninfo=="radio"||questioninfo=="judge"||questioninfo=="mulit"){
$("#"+questioninfo).html($("#"+questioninfo).html()+" (正确答案:"+item.rightkey+")"+" <span style='padding-left:15px;'>得分:"+item.score+"分<span>");
if(questioninfo!="mulit"){
$("#"+item.questionid+"_"+item.useranswer).attr("checked",true);
}else{
var userswers=item.useranswer.split(",");
$.each(userswers,function(anindex,anitem){
$("#"+item.questionid+"_"+anitem).attr("checked",true);
});
}
}
if(questioninfo=="textarea"){
if(item.score!="批改中"){
$("#"+questioninfo).html($("#"+questioninfo).html()+" <span style='padding-left:15px;'>得分:"+item.score+"分<span>");
}else{
$("#"+questioninfo).html($("#"+questioninfo).html()+" <span style='padding-left:15px;'>得分:"+item.score+"<span>");
}
$("#"+item.questionid).val(item.useranswer);
var questanaly="暂无解析";
if(item.rightkey!="null")
questanaly=item.rightkey;
$("#textarea_"+questioninfo).parent().append("<p>解析:"+questanaly+"</p>");
}
});
}
var userexamsum=data.examsumscore*0.6+"";
if(userexamsum.length>5)
userexamsum=userexamsum.substring(0,5);
var useranwser_infohtml="<p><b>试卷总分:</b>"+data.examsumscore+"分</p>";
useranwser_infohtml+="<p><b>单选题得分:</b>"+data.optionscore+"</p>";
useranwser_infohtml+="<p><b>多选题得分:</b>"+data.mulitscore+"</p>";
useranwser_infohtml+="<p><b>判断题得分:</b>"+data.judgescore+"</p>";
useranwser_infohtml+="<p><b>论述题得分:</b>"+data.essayscore+"</p>";
useranwser_infohtml+="<p><b>总得分:"+data.usersumscore+"</b></p>";
useranwser_infohtml+="<br><p><font color='#ff0000'>Tip:得分达到总分60%("+userexamsum+"分),视为合格!</font></p>";
$("#useranwser_info").html(useranwser_infohtml);
},
error:function(){
showMessage("获取用户答题记录失败!");
},
dataType:'json',
type:'post',
data:{
'scoreid':'null'
}
});
}
</script>
F12 console
输入getuseranswer()
回车会运行getuseranswer
返回?好像并没有return,只是修改了html页面$("#useranwser_info") 在控制台输入函数名执行就行吧
现在具体是什么问题 有报错吗 1.按F12
2.点击console
3.输入方法名
4.回车执行 执行后这么显示 xfzsun 发表于 2022-3-3 10:00
执行后这么显示
你这个源页面没有引入jquery的js
页:
[1]