var webroot = $("#hdWebroot").val(); var rootUrl = webroot + '/exam/exampaper/'; var save_editexampaper_Url = rootUrl + 'save_editexampaper';//编辑试卷内容 保存数据地址 var delete_editexampaper_Url = rootUrl + 'delete_editexampaper';//编辑试卷内容 删除数据地址 var countNumberUrl = rootUrl + 'countNumber';//编辑试卷内容 计算题目数量 var calculateScoreUrl = rootUrl + 'calculateScore';//编辑试卷内容 计算分值 var setNumberUrl = rootUrl + 'setNumber';//加题后 排序 var setDeleteNumberUrl = rootUrl + 'setDeleteNumber';//删题后 排序 var moveUpUrl = rootUrl + 'moveUp';//上移 var moveDownUrl = rootUrl + 'moveDown';//下移 var isEditingFlag = false; //是否有题目处于正在编辑状态 var addQ = 0; var addP = 0; var pg_ = "";//控制考试与调研页面交替,1考试2调研 pg_ = $('#pg').val(); //此方法需要实现从后台获取到当前试卷增加新题目时,题目的题号 function getNewQuestionNum() { return 6+addQ++; } //此方法需要实现从后台获取到当前试卷增加新题目或者段落时,其位置号 function getNewPositionNum() { return 6+addP++; } var item = { id: '', subject: '', type: '', isMust: '', optionA: '', optionB: '', optionC: '', optionD: '', optionE: '', optionF: '', score: '', num: '', isParagraph:'', answer:'' }; function deleteData(confirmText, url, data, callback) { $.uiMessagebox.confirm({ title: '确认操作', content: confirmText, onClose: function (value) { if (value) { callback && callback.call(this, value); // alert(value); // return value; // $.ajax({ // type: 'post', // url: url, // data: data, // dataType: "json", // success: function (result) { // callback && callback.call(this, result); // } // }); } } }); } //编辑问题 function editquestion(e) { var count=$('#eqlist2').find("button").length;//计算页面中有多少个button按钮,使用length方法 if(count > 1) { alert("请先保存上一题目再进行下一题的编辑!"); return; } isEditingFlag = true; var itr = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr gettrdata(itr); var eqhtml=''+ '
'+ ''+ // 'Q'+ 'Q'+ //'Q'+item.num + //' '+ ' '+ ' '+ ' 必答'+ // ' < style="width: 8%">'+ // ' '+ ''+item.type+''+ // ''+ ''+ // '<#if pg=="1">'+ ''+ ''+ // ''+ //''+'分'+''+ '
'; // if(item.type=="1" || item.type=="2") { if(item.type=="单选题" || item.type=="多选题") { if (item.optionA != null && item.optionA.length > 0) eqhtml += '
A
'; if (item.optionB != null && item.optionB.length > 0) eqhtml += '
B
'; if (item.optionC != null && item.optionC.length > 0) eqhtml += '
C
'; if (item.optionD != null && item.optionD.length > 0) eqhtml += '
D
'; if (item.optionE != null && item.optionE.length > 0) eqhtml += '
E
'; if (item.optionF != null && item.optionF.length > 0) eqhtml += '
F
'; } if(item.type=="问答题") eqhtml +='
答案:

'; if(item.type=="填空题") { eqhtml +='输入完整的题目后,从题目开始按顺序依次选中需要填空的文字点击“设为空格”
'+ '答案:
'; } if(item.type=="单选题") { eqhtml += ''; } if(item.type=="多选题") { eqhtml += ''; } if(item.type=="判断题"){ eqhtml += '
'+ 'A 对'+ ''+ '
'+ '
'+ 'B 错'+ ''+ '
' } eqhtml += ''; eqhtml += ''; eqhtml += ''; // if(item.isMust=="1") // { // $('#cb').prop('checked'); // } // itr.parent().find("tr:eq("+ (item.order -1)+")").append(eqhtml); itr.html(""); itr.html(eqhtml); if(item.type=="单选题" || item.type=="判断题"){ checkBox(); } item = { id: '', subject: '', type: '', isMust: '', optionA: '', optionB: '', optionC: '', optionD: '', optionE: '', optionF: '', score: '', num: '', isParagraph:'' }; // alert(item.a1); // itr.remove(); // alert(this.find(div).id); // alert($("#"+id).attr("id")); // $("#"+id).find("table").hide(); // $("#xzt").show(); // $("#"+id).append($("#xzt").html()) } //保存问题 function savequestion(e,tk,sort) {//tk 1保存2存题库 sort 1排序2不排序 var parent = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr var editexampaper_id = parent.find(".qid").html();//每一题的id var edit_id=""; var num=""; var subject=""; var type=""; var type_num=""; var ismust=""; var score=""; var a=""; var b=""; var c=""; var d=""; var ee=""; var f=""; var isParagraph = 0; var answer=""; var category = "";//试卷类别 var categoryid = "";//试卷类别id category = category_; categoryid = categoryid_; edit_id =AndEdit_id;//试卷的id num = parent.find('#question_numid').val(); subject = parent.find('#subject').val(); if($.trim(subject) == ''){//trim函数 去掉空格 alert("请先填写题目再保存!"); return; } if(parent.find('#subject').val().length > 200){ alert("题目限制200个字符,请修改后保存!"); return; } type = parent.find('#questiontype').text(); type_num; if(type == "单选题"){ type_num = 1; }else if(type == "多选题"){ type_num = 2; }else if(type == "判断题"){ type_num = 3; }else if(type == "填空题"){ type_num = 4; }else if(type == "问答题"){ type_num = 5; } if(parent.find('#cb').prop('checked')){ ismust = 1; }else{ ismust = 0; } if($('#pg').val() == "1"){ score =parent.find('#score').val(); if($.trim(score) == ''){//trim函数 去掉空格 alert("请先设置分数再保存!"); return; } } if(typeof (parent.find('#a').val()) !== "undefined") { a = parent.find("#a").val(); if ($.trim(a) == '') {//trim函数 去掉空格 alert("请先填写选项A再保存!"); return; } if(a.length > 100){ alert("选项限制100个字符,请修改后保存!"); return; } } if(typeof (parent.find('#b').val()) !== "undefined") { b = parent.find("#b").val(); if ($.trim(b) == '') {//trim函数 去掉空格 alert("请先填写选项B再保存!"); return; } if(b.length > 100){ alert("选项限制100个字符,请修改后保存!"); return; } } if(typeof (parent.find('#c').val()) !== "undefined") { c = parent.find("#c").val(); if ($.trim(c) == '') {//trim函数 去掉空格 alert("请先填写选项C再保存!"); return; } if(c.length > 100){ alert("选项限制100个字符,请修改后保存!"); return; } } if(typeof (parent.find('#d').val()) !== "undefined") { d = parent.find("#d").val(); if ($.trim(d) == '') {//trim函数 去掉空格 alert("请先填写选项D再保存!"); return; } if(d.length > 100){ alert("选项限制100个字符,请修改后保存!"); return; } } if(type == "多选题") { if (typeof (parent.find('#e').val()) !== "undefined") { ee = parent.find("#e").val(); if ($.trim(ee) == '') {//trim函数 去掉空格 alert("请先填写选项E再保存!"); return; } if(ee.length > 100){ alert("选项限制100个字符,请修改后保存!"); return; } } if (typeof (parent.find('#f').val()) !== "undefined") { f = parent.find("#f").val(); if ($.trim(f) == '') {//trim函数 去掉空格 alert("请先填写选项F再保存!"); return; } if(f.length > 100){ alert("选项限制100个字符,请修改后保存!"); return; } } } if(parent.find('#cbA').prop('checked')){ answer += "A"; if(type == "判断题") { answer = "对"; } } if (parent.find('#cbB').prop('checked')){ answer += "B"; if(type == "判断题") { answer = "错"; } } if (parent.find('#cbC').prop('checked')){ answer += "C"; } if (parent.find('#cbD').prop('checked')){ answer += "D"; } if (parent.find('#cbE').prop('checked')){ answer += "E"; } if (parent.find('#cbF').prop('checked')){ answer += "F"; } if(type == "问答题" || type == "填空题") { // answer = $('#answer').val();//页面中有多个id为answer的标签,该方法只能获取第一个的 answer = parent.find(".answer").val();//该方法可以获取最近的class为q_iem的标签的内容 } if($('#pg').val() == "1"){ if($.trim(answer) == ''){//trim函数 去掉空格 alert("请先填写答案再保存!"); return; } if(answer.length > 2000){ alert("答案限制2000个字符,请修改后保存!"); return; } } //保存题目 $.ajax({ type: 'post', url: save_editexampaper_Url, data: {'id':editexampaper_id, 'edit_id':edit_id, 'num':num, 'subject':subject, 'type':type, 'type_num':type_num, 'ismust':ismust, 'score':score, 'optionA':a, 'optionB':b, 'optionC':c, 'optionD':d, 'optionE':ee, 'optionF':f, 'isParagraph':isParagraph, 'answer':answer, 'tk':tk, 'category':category, 'categoryid':categoryid}, dataType: "json", success: function (result) { if (result.success) { if(sort == '1'){ //排序 $.ajax({ type: 'post', url: setNumberUrl, data: {'id':result.data.questionId, 'edit_id':edit_id, 'num':num, 'type_num':type_num}, dataType: "json", success: function (result) { if (result.success) { $('#eqlist2').uiGrid('loadData'); } showResult(result.success, result.message); }, error:function() { alert("排序失败"); } }); }else{ $('#eqlist2').uiGrid('loadData'); } } showResult(result.success, result.message); }, error:function() { alert("保存题目失败"); } }); var itr = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr getinputdata(itr); // var tname = ''; // if(item.type==1) tname='单选题'; // else if(item.type==2) tname='多选题'; // else if(item.type==3) tname='判断题'; // else if(item.type==4) tname='问答题'; var tname = item.type; var eqhtml=''+ '
'+ ''+ // ''+ 'Q'+item.num+' '+''+ ''+item.subject+''+ tname+ ''+ (item.isMust=="1"?"(必答)":"(选答)")+ ''+ ''+ //''+ ''+ ''+ // ''+ ''+ ''+ ''+item.score+''+ '
'; // if(item.type==1 || item.type==2) { if(item.type=="单选题" || item.type=="多选题") { if (item.optionA != null && item.optionA.length > 0) eqhtml += '
A' +' '+ item.optionA + '
'; if (item.optionB != null && item.optionB.length > 0) eqhtml += '
B' +' '+ item.optionB + '
'; if (item.optionC != null && item.optionC.length > 0) eqhtml += '
C' +' '+ item.optionC + '
'; if (item.optionD != null && item.optionD.length > 0) eqhtml += '
D' +' '+ item.optionD + '
'; if (item.optionE != null && item.optionE.length > 0) eqhtml += '
E' +' '+ item.optionE + '
'; if (item.optionF != null && item.optionF.length > 0) eqhtml += '
F' +' '+ item.optionF + '
'; } //if(item.qtype==4) eqhtml +='
'; } // itr.parent().find("tr:eq("+ (item.order -1)+")").append(eqhtml); itr.html("");//将添加的题清空,保存成功之后会使用ajax里的$('#eqlist2').uiGrid('loadData')刷新并重新排列题目 itr.html(eqhtml).hide();//隐藏掉是为了避免添加的题仍然存在 item = { id: '', subject: '', type: '', isMust: '', optionA: '', optionB: '', optionC: '', optionD: '', optionE: '', optionF: '', score: '', num: '', isParagraph:'' }; //保存成功后,将flag设为false isEditingFlag = false; setStatistic(); } //添加选项 function additem(e) { var obj = $(e).parents().filter('td:eq(0)').find('.q_item').last(); var n = obj[0].children[0].innerHTML; var type = $(e).parents().find('#questiontype').html(); if(type === "单选题" && n === "D"){ alert("单选题最多支持4个候选项!"); return; } if(type === "多选题" && n === "F"){ alert("多选题最多支持6个候选项!"); return; } var value_id = ''; var value = ''; switch(n){ case 'A': value_id='b'; value = 'B';break; case 'B': value_id='c'; value = 'C';break; case 'C': value_id='d'; value = 'D';break; case 'D': value_id='e'; value = 'E';break; case 'E': value_id='f'; value = 'F';break; case 'F': return; case '': return; } var ihtml = '
' + '' + value +'  '+ '' + ' ' + '' + '
'; obj.after(ihtml); } //移除选项 可以视为更新,将某选项设置为空即可 function deleteitem(e) { var parent = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr var editexampaper_id = parent.find(".qid").html();//每一题的id if(editexampaper_id == ""){ var idiv = $(e).parents().filter('div:eq(0)'); idiv.remove(); } else { var idiv = $(e).parents().filter('div:eq(0)'); idiv.remove(); var a = ""; var b = ""; var c = ""; var d = ""; var ee= ""; var f = ""; if(typeof ($('#a').val()) !== "undefined") { a = $('#a').val(); } if(typeof ($('#b').val()) !== "undefined") { b = $('#b').val(); } if(typeof ($('#c').val()) !== "undefined") { c = $('#c').val(); } if(typeof ($('#d').val()) !== "undefined") { d = $('#d').val(); } if(typeof ($('#e').val()) !== "undefined") { ee = $('#e').val(); } if(typeof ($('#f').val()) !== "undefined") { f = $('#f').val(); } // var answer=""; // if($('#cbA').prop('checked')){ // answer += "A"; // } // if ($('#cbB').prop('checked')){ // answer += "B"; // } // if ($('#cbC').prop('checked')){ // answer += "C"; // } // if ($('#cbD').prop('checked')){ // answer += "D"; // } // if ($('#cbE').prop('checked')){ // answer += "E"; // } // if ($('#cbD').prop('checked')){ // answer += "F"; // } $.ajax({ type: 'post', url: save_editexampaper_Url, data: {'id':editexampaper_id, 'optionA':a, 'optionB':b, 'optionC':c, 'optionD':d, 'optionE':ee, 'optionF':f // 'answer':answer }, dataType: "json", success: function (result) { if (result.success) { //$('#eqlist2').uiGrid('loadData'); } showResult(result.success, result.message); }, error:function() { alert("提交失败"); } }); } } //添加题目 function addquestion(e, type) { var count=$('#eqlist2').find("button").length;//计算页面中有多少个button按钮,使用length方法 if(count > 0) { alert("请先保存上一题目再添加下一题!"); return; } isEditingFlag = true; var nextnum = $("#eqlist2").find('tr').length + 1; var qhtml = ' '; if (type == "1") { qhtml += $("#add1").html(); } if (type == "2") { qhtml += $("#add2").html(); } if (type == "3" ) { qhtml += $("#add3").html(); } if (type == "4" ) { qhtml += $("#add4").html(); } if (type == "5" ) { qhtml += $("#add5").html(); } qhtml += ''; $("#eqlist2").find('tr').last().after(qhtml); $("#eqlist2 .grid_data").last()[0].scrollTop = $("#eqlist2 .grid_data").last()[0].scrollHeight; if (type == "1" || type == "3"){ checkBox(); } } //移除题目 // function deletequestion(e,position) { function deletequestion(e) { var parent = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr var editexampaper_id = parent.find(".qid").html();//每一题的id var num = ""; var edit_id = ""; num = parent.find('#q_numid').text();//序号 if(num == ""){ num = parent.find('#q_numid').val();//序号 } edit_id = AndEdit_id;//试卷id if(editexampaper_id == ""){ $(e).parents().filter('tr:eq(0)').remove(); setStatistic();//计算题数和总分 } else { $.uiMessagebox.confirm({ title: '确认操作', content: "此操作将删除信息,确定删除吗?", onClose: function (value) { if (value) { $.ajax({ type: 'post', url: delete_editexampaper_Url, data: {ids: editexampaper_id}, dataType: "json", success: function (result) { if(result.success){ $('#eqlist2').uiGrid('loadData');//重新刷新查询时没有用queryParams传入参数,为什么可以查询成功? $(e).parents().filter('tr:eq(0)').remove(); setStatistic();//计算题数和总分 //排序 $.ajax({ type: 'post', url: setDeleteNumberUrl, data: {'edit_id':edit_id, 'num':num}, dataType: "json", success: function (result) { if (result.success) { $('#eqlist2').uiGrid('loadData'); } showResult(result.success, result.message); }, error:function() { alert("排序失败"); } }); } showResult(result.success, result.message); } }); } } }); } // $(e).parents().filter('table:eq(0)').remove(); } //获取tr数据 编辑 function gettrdata(e) { item.id = e.find(".qid").html(); item.num = e.find(".qxh").html(); item.subject = e.find(".qtm").html(); item.type = e.find(".qtype").html(); item.isMust = e.find(".qbd").html(); item.score = e.find(".score").html(); item.isParagraph = 0; item.answer = e.find(".answer").html(); // item.answer = e.find(".q_item").html(); item.optionA = e.find(".q_item:eq(0)").find("span").html(); if (e.find(".q_item:eq(1)") != null) item.optionB = e.find(".q_item:eq(1)").find("span").html(); if (e.find(".q_item:eq(2)") != null) item.optionC = e.find(".q_item:eq(2)").find("span").html(); if (e.find(".q_item:eq(3)") != null) item.optionD = e.find(".q_item:eq(3)").find("span").html(); if (e.find(".q_item:eq(4)") != null) item.optionE = e.find(".q_item:eq(4)").find("span").html(); if (e.find(".q_item:eq(5)") != null) item.optionF = e.find(".q_item:eq(5)").find("span").html(); } //获取input数据 保存 function getinputdata(e) { item.id = e.find(".qid").html(); item.num = e.find("#question_numid").val(); item.subject = e.find("#subject").val(); item.type = e.find("#questiontype").text(); if($('#cb').prop('checked')){ item.isMust = 1; }else{ item.isMust = 0; } item.score = e.find("#score").val(); item.isParagraph = 0; item.answer = e.find(".answer").html(); item.optionA = e.find(".q_item:eq(0)").find("input").val(); if(item.type=="单选题" || item.type=="多选题") { if (e.find(".q_item:eq(1)") != null) item.optionB = e.find(".q_item:eq(1)").find("input").val(); if (e.find(".q_item:eq(2)") != null) item.optionC = e.find(".q_item:eq(2)").find("input").val(); if (e.find(".q_item:eq(3)") != null) item.optionD = e.find(".q_item:eq(3)").find("input").val(); if (e.find(".q_item:eq(4)") != null) item.optionE = e.find(".q_item:eq(4)").find("input").val(); if (e.find(".q_item:eq(5)") != null) item.optionF = e.find(".q_item:eq(5)").find("input").val(); } // item.id = e.find(".qid").html(); // item.num = e.find(".qxh").html(); // item.subject = e.find(".qtm").html(); // item.type = e.find(".type").html(); // item.isMust = e.find(".qbd").html(); // item.optionA = e.find(".q_item:eq(0)").find("input").val(); // if(item.qtype==1 || item.qtype==2) { // if (e.find(".q_item:eq(1)") != null) // item.optionB = e.find(".q_item:eq(1)").find("input").val(); // if (e.find(".q_item:eq(2)") != null) // item.optionC = e.find(".q_item:eq(2)").find("input").val(); // if (e.find(".q_item:eq(3)") != null) // item.optionD = e.find(".q_item:eq(3)").find("input").val(); // if (e.find(".q_item:eq(4)") != null) // item.optionE = e.find(".q_item:eq(4)").find("input").val(); // if (e.find(".q_item:eq(5)") != null) // item.optionF = e.find(".q_item:eq(5)").find("input").val(); // } } //选择添加题目方式 function selectaddtype(type) { switch(type) { case '0': $('#exceldr').show(); $('#sj').hide(); $('#sls').hide(); // $('#eqlist2').uiGrid('loadData'); break; case '1': $('#exceldr').hide(); $('#sj').show(); $('#sls').hide(); // $('#eqlist2').uiGrid('loadData'); break; case '2': $('#exceldr').hide(); $('#sj').hide(); $('#sls').show(); // $('#eqlist2').uiGrid('loadData'); break; } } //单项选择ABCD function checkBox() { $('#cbA').bind('click',function (){ if($('#cbA').prop('checked')) { $('#cbB').prop('checked',false); $('#cbC').prop('checked',false); $('#cbD').prop('checked',false); } }); $('#cbB').bind('click',function (){ if($('#cbB').prop('checked')) { $('#cbA').prop('checked',false); $('#cbC').prop('checked',false); $('#cbD').prop('checked',false); } }); $('#cbC').bind('click',function (){ if($('#cbC').prop('checked')) { $('#cbB').prop('checked',false); $('#cbA').prop('checked',false); $('#cbD').prop('checked',false); } }); $('#cbD').bind('click',function (){ if($('#cbD').prop('checked')) { $('#cbB').prop('checked',false); $('#cbC').prop('checked',false); $('#cbA').prop('checked',false); } }); } //设为空格 function setSpace(e) { var parent = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr // var t = $('#subject')[0]; var t = parent.find("#subject")[0]; //var t = $('#subject').get(0);//等同于$('#subject')[0] //var t = document.getElementById('subject');//js写法,等同于$('#subject')[0]和$('#subject').get(0) // if (window.getSelection) {//IE8不支持,谷歌等支持的写法 if (document.selection) {//IE8支持,谷歌等不支持的写法 // if (t.selectionStart != undefined && t.selectionEnd != undefined && t.selectionStart != t.selectionEnd) {//IE8不支持,谷歌等支持的写法 if (document.selection.createRange().text != '' && document.selection.createRange().text != $('#txtsubject').val()) {//IE8支持,谷歌等不支持的写法 // var previous_answer = $('#answer').val(); var previous_answer = parent.find("#answer").val(); // var answer = t.value.substring(t.selectionStart, t.selectionEnd);//IE8不支持,谷歌等支持的写法 var answer = document.selection.createRange().text;//IE8支持,谷歌等不支持的写法 if(previous_answer != "") { answer = previous_answer + "," + answer; } // $('#answer').val(answer); parent.find("#answer").val(answer); // var a = t.value.substring(t.selectionStart, t.selectionEnd);//IE8不支持,谷歌等支持的写法 var a = document.selection.createRange().text;//IE8支持,谷歌等不支持的写法 var b=t.value; //t.val(b.replace(a,"__"));//错误 // $('#subject').val(b.replace(a,"____")); parent.find("#subject").val(b.replace(a,"____")); } else { return; } } else { return; } } //计算题数和总分 function setStatistic() { var totalQuestion=""; var totalScore=0; var score=""; if($('#eqlist2').find('tbody tr').length == 0 && $('#eqlist2').find('thead tr').length == 2){//第一次添加题目时,tbody中没有tr,而在thead中有2个tr,所以单独做判断 totalQuestion = $('#eqlist2').find('tbody tr').length + 1; totalScore = $('#eqlist2').find('tr:eq(1)').find(".score").html(); $('#sum').val(totalQuestion); $('#sum_score').val(totalScore); return; } for (var i=0; i<$('#eqlist2').find('tbody tr').length; i++){ var parent=""; parent=$('#eqlist2').find('tbody tr:eq('+i+')'); score=parent.find(".score").html(); totalScore +=Number(score); } totalQuestion = $('#eqlist2').find('tbody tr').length; $('#sum').val(totalQuestion); $('#sum_score').val(totalScore); // for (var i=1; i<$('#eqlist2').find('tr').length; i++){ // var parent=""; // parent=$('#eqlist2').find('tr:eq('+i+')'); // score=parent.find(".score").html(); // totalScore +=Number(score); // } // totalQuestion = $('#eqlist2').find('tr').length - 1; // $('#sum').val(totalQuestion); // $('#sum_score').val(totalScore); } //计算题数和总分 预览 function setStatistic_preview() { var totalQuestion=""; var totalScore=0; var score=""; for (var i=0; i<$('#eqlist2_preview').find('tbody tr').length; i++){ var parent=""; parent=$('#eqlist2_preview').find('tbody tr:eq('+i+')'); score=parent.find(".score").html(); totalScore +=Number(score); } totalQuestion = $('#eqlist2_preview').find('tbody tr').length; $('#sum_preview').val(totalQuestion); $('#sum_score_preview').val(totalScore); } //计算分值 未使用 function setCalculate(e) { var single=""; var multiple=""; var judgement=""; var blank=""; var essay=""; var sum=""; var single_score=""; var multiple_score=""; var judgement_score=""; var blank_score=""; var essay_score=""; var sum_score=""; var q_count1=-1; var q_count2=-1; var q_count3=-1; var q_count4=-1; var q_count5=-1; single=$('#single').val(); multiple=$("#multiple").val(); judgement=$("#judgement").val(); blank=$("#blank").val(); essay=$("#essay").val(); single_score=$("#single_score").val(); multiple_score=$("#multiple_score").val(); judgement_score=$("#judgement_score").val(); blank_score=$("#blank_score").val(); essay_score=$("#essay_score").val(); $.ajax({ type: 'post', url: countNumberUrl, data:{'AndEdit_id':AndEdit_id}, dataType: "json", success: function (result) { //result是接收后台return的结果 //showResult(result.success, result.message); var value=result.data.rows[0]; q_count1=value.q_count1; q_count2=value.q_count2; q_count3=value.q_count3; q_count4=value.q_count4; q_count5=value.q_count5; // $('#eqlist2').uiGrid('loadData'); if(single != q_count1){ alert("输入的单选题数量与试卷中的单选题数量不符!请重新输入"); return; } if(multiple != q_count2){ alert("输入的多选题数量与试卷中的多选题数量不符!请重新输入"); return; } if(judgement != q_count3){ alert("输入的判断题数量与试卷中的判断题数量不符!请重新输入"); return; } if(blank != q_count4){ alert("输入的填空题数量与试卷中的填空题数量不符!请重新输入"); return; } if(essay != q_count5){ alert("输入的问答题数量与试卷中的问答题数量不符!请重新输入"); return; } }, error:function() { alert("计算题目数量失败"); } }); sum=Number(single)+Number(multiple)+Number(judgement)+Number(blank)+Number(essay); $('#sum').val(sum); var singleEachScore = single_score / single; var multipleEachScore = multiple_score / multiple; var judgementEachScore = judgement_score / judgement; var blankEachScore = blank_score / blank; var essayEachScore = essay_score / essay; var parent = $('#eqlist2').find('tr:eq('+i+')'); var exampapereditInfo={id:[], score:[]}; var i = 1; for(i; i<=Number(single); i++){ var parent = $('#eqlist2').find('tr:eq('+i+')'); exampapereditInfo.id[i-1] = parent.find(".qid").html(); exampapereditInfo.score[i-1] = singleEachScore; } for(i; i<=Number(single)+Number(multiple); i++){ var parent = $('#eqlist2').find('tr:eq('+i+')'); exampapereditInfo.id[i-1] = parent.find(".qid").html(); exampapereditInfo.score[i-1] = multipleEachScore; } for(i; i<=Number(single)+Number(multiple)+Number(judgement); i++){ var parent = $('#eqlist2').find('tr:eq('+i+')'); exampapereditInfo.id[i-1] = parent.find(".qid").html(); exampapereditInfo.score[i-1] = judgementEachScore; } for(i; i<=Number(single)+Number(multiple)+Number(judgement)+Number(blank); i++){ var parent = $('#eqlist2').find('tr:eq('+i+')'); exampapereditInfo.id[i-1] = parent.find(".qid").html(); exampapereditInfo.score[i-1] = blankEachScore; } for(i; i<=Number(sum); i++){ var parent = $('#eqlist2').find('tr:eq('+i+')'); exampapereditInfo.id[i-1] = parent.find(".qid").html(); exampapereditInfo.score[i-1] = essayEachScore; } $.ajax({ type: 'post', url: calculateScoreUrl, data:{'exampapereditInfoList':JSON.stringify(exampapereditInfo)}, dataType: "json", success: function (result) { //result是接收后台return的结果 }, error:function() { alert("计算题目分值失败"); } }); } //取消 function cancel() { $('#eqlist2').uiGrid('loadData'); } //上移 function moveUp(e) { var parent = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr var editexampaper_id = parent.find(".qid").html();//每一题的id var edit_id=""; var num=""; var type=""; var type_num=""; type = parent.find('.qtype').text(); type_num; if(type == "单选题"){ type_num = 1; }else if(type == "多选题"){ type_num = 2; }else if(type == "判断题"){ type_num = 3; }else if(type == "填空题"){ type_num = 4; }else if(type == "问答题"){ type_num = 5; } edit_id =AndEdit_id;//试卷的id num = parent.find('#q_numid').text();//序号 if(num == "1"){ alert("第一题不再允许上移!"); return; } $.ajax({ type: 'post', url: moveUpUrl, data: {'id':editexampaper_id, 'edit_id':edit_id, 'num':num, 'type_num':type_num}, dataType: "json", success: function (result) { if (result.success) { $('#eqlist2').uiGrid('loadData'); } showResult(result.success, result.message); }, error:function() { alert("上移失败"); } }); } //下移 function moveDown(e) { var parent = $(e).parents().filter('tr:eq(0)');//下标等于0的tr,即第1个tr var editexampaper_id = parent.find(".qid").html();//每一题的id var edit_id=""; var num=""; var type=""; var type_num=""; type = parent.find('.qtype').text(); type_num; if(type == "单选题"){ type_num = 1; }else if(type == "多选题"){ type_num = 2; }else if(type == "判断题"){ type_num = 3; }else if(type == "填空题"){ type_num = 4; }else if(type == "问答题"){ type_num = 5; } edit_id =AndEdit_id;//试卷的id num = parent.find('#q_numid').text();//序号 var totalQuestion = $('#eqlist2').find('tbody tr').length; if(num == totalQuestion){ alert("最后一题不再允许下移!"); return; } $.ajax({ type: 'post', url: moveDownUrl, data: {'id':editexampaper_id, 'edit_id':edit_id, 'num':num, 'type_num':type_num}, dataType: "json", success: function (result) { if (result.success) { $('#eqlist2').uiGrid('loadData'); } showResult(result.success, result.message); }, error:function() { alert("下移失败"); } }); }