更多操作
无编辑摘要 标签:已被回退 |
小 (导入1个版本) |
||
(未显示同一用户的7个中间版本) | |||
第1行: | 第1行: | ||
/ | //设置 | ||
var prefixDic = { | |||
formId:'timuForm-', | |||
radioName:'radio-', | |||
radioId:'radio-input-', | |||
checkBoxName:'checkbox-', | |||
checkBoxId:'checkbox-input-', | |||
selectId:'select-', | |||
selectName:'select-', | |||
textInputName:'text-', | |||
textInputId:'text-' | |||
} | |||
//主函数 | //主函数 | ||
function renderTimuFromSessionStorage(){ | function renderTimuFromSessionStorage(){ | ||
var timuList = gDomTimuList() | var timuList = gDomTimuList() | ||
console.log(timuList) | // console.log(timuList) | ||
var order = timuList.order | var order = timuList.order | ||
var timu = timuList.timu | var timu = timuList.timu | ||
第79行: | 第85行: | ||
//从有中文的source中提取最后一个连续数字作为真实的source | //从有中文的source中提取最后一个连续数字作为真实的source | ||
function getRealSource(source){ | function getRealSource(source){ | ||
console.log(source) | // console.log(source) | ||
var getContinueNumber = source.match(/[0-9]+/g) | var getContinueNumber = source.match(/[0-9]+/g) | ||
var splitContinueNumber = source.split(/[0-9]+/g) | var splitContinueNumber = source.split(/[0-9]+/g) | ||
第113行: | 第119行: | ||
return $('<p class="title">'+title+'</p>') | return $('<p class="title">'+title+'</p>') | ||
} | } | ||
//生成buttonGroup | //生成buttonGroup | ||
function buttonGroup(showSubmitBtn, showEditBtn, id, type, correctAnswer, hoverTarget){ | function buttonGroup(showSubmitBtn, showEditBtn, id, type, correctAnswer, hoverTarget){ | ||
console.log(showEditBtn) | // console.log(showEditBtn) | ||
var buttonGroupObj = $('<div class="buttonGroup"></div>') | var buttonGroupObj = $('<div class="buttonGroup"></div>') | ||
if(showSubmitBtn){buttonGroupObj.append( | if(showSubmitBtn){buttonGroupObj.append( | ||
第178行: | 第145行: | ||
], | ], | ||
icon: 'edit', | icon: 'edit', | ||
label: ' | label: '题目有误?点击编辑本题' | ||
} ).$element.bind("click",function (){ | } ).$element.bind("click",function (){ | ||
editThis(id) | editThis(id) | ||
第191行: | 第158行: | ||
return buttonGroupObj | return buttonGroupObj | ||
} | } | ||
//resultGroup: answer和explain的显示框 | //resultGroup: answer和explain的显示框 | ||
function resultGroup(id, items, answerInline,explainInline){ | function resultGroup(id, items, answerInline,explainInline){ | ||
第216行: | 第174行: | ||
return $('<div class="explainInline"><label>解析:</label>'+explain+'</div>') | return $('<div class="explainInline"><label>解析:</label>'+explain+'</div>') | ||
} | } | ||
//生成subject 的form, 顺序items顺序添加 (title, options, buttonGroup) | |||
function subjectFrom(id, type, items){ | |||
var form = $('<form id="'+prefixDic.formId+id+'" class="subjectForm"></form>') | |||
//绑定变化事件 | |||
form.change(function(){ | |||
// 如果开启了暂存,则暂存 | |||
if(!gWebPageTimuSettings().noTemp){ | |||
formChangeListener(id, type) | |||
} | |||
}) | |||
for(var i=0;i<items.length;i++){ | |||
form.append(items[i]) | |||
} | |||
return form | |||
} | |||
function subjectDIV(id,type,items){ | |||
var div= $('<div id="'+prefixDic.formId+id+'" class="subjectForm"></div>') | |||
for(var i=0;i<items.length;i++){ | |||
div.append(items[i]) | |||
} | |||
return div | |||
} | |||
//生成填空输入框 | //生成填空输入框 | ||
function fillBlank(id, title, pos, classes){ | function fillBlank(id, title, pos, classes){ | ||
console.log(pos) | // console.log(pos) | ||
var posReg = new RegExp(pos,'g') | var posReg = new RegExp(pos,'g') | ||
var blankLen = title.match(posReg).length | var blankLen = title.match(posReg).length | ||
var split = title.split(posReg) | var split = title.split(posReg) | ||
console.log(blankLen) | // console.log(blankLen) | ||
var newTitle = '' | var newTitle = '' | ||
for(var i=0;i<(blankLen+split.length);i++){ | for(var i=0;i<(blankLen+split.length);i++){ | ||
第229行: | 第211行: | ||
}else{ | }else{ | ||
newTitle += new OO.ui.TextInputWidget( { | newTitle += new OO.ui.TextInputWidget( { | ||
name: | name:prefixDic.textInputName+id+'-'+Math.floor(i/2), | ||
id: | id:prefixDic.textInputId+id+'-'+Math.floor(i/2), | ||
classes:classes | classes:classes | ||
} ).$element.prop('outerHTML') | } ).$element.prop('outerHTML') | ||
第238行: | 第220行: | ||
return newTitle | return newTitle | ||
} | } | ||
//生成B、C型题的选择框 | |||
function dropDownInputWidget(id, availabelOptions){ | |||
var options = [] | |||
var select = $('<select class="dorpdown" id="'+prefixDic.selectId+id+'" name="'+prefixDic.selectName+id+'"></select>') | |||
for(var i=0;i<availabelOptions.length;i++){ | |||
select.append('<option class="dropdown-option" value="'+availabelOptions[i]+'">'+availabelOptions[i]+'</option>') | |||
} | |||
return select | |||
} | |||
//生成options(options 是 Map对象) | |||
function optionsGroup(type,id,options){ | |||
var flexClass = (type==='B')||(type==='C') ? 'optionsGroup-flex':'' | |||
var inputType = type==='X' ? 'checkbox':'radio' | |||
var optionGroupObj = $('<div class="optionsGroup '+flexClass+'"></div>') | |||
options.forEach(function(value, key, map){ | |||
optionGroupObj.append(optionInline(id, key, value, !((type==='B')||(type==='C')), inputType)) | |||
}) | |||
return optionGroupObj | |||
} | |||
//生成optionInline | |||
function optionInline(id, option, content,input,inputType){ | |||
var idPrefix = inputType === 'checkbox' ? prefixDic.checkBoxId:prefixDic.radioId | |||
var namePrefix = inputType === 'checkbox' ? prefixDic.checkBoxName:prefixDic.radioName // 这个和外部的div的id一样就共用了 | |||
var input = input ? $('<input id="'+ idPrefix + id+'-'+option+'" name="'+ namePrefix + id + '" type="'+inputType+'" value="' + option + '" />'):'' | |||
var optionLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+option+'. </label>') | |||
var contentLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+content+'</label>') | |||
return $('<div id="'+ namePrefix +id+'-'+option+'" class="optionInline"></div>').append(input,optionLabel,contentLabel) | |||
} | |||
//清理json中的choice(清除空项并排序),接收Obj, | |||
function cleanAndMakeSameLenOptions(options){ | |||
//清除空项 | |||
var options = filterEmptyEntries(options) | |||
//让所有option长度一样 | |||
var maxOptionLen = getStrLength(Object.values(options).sort(function(a,b){return getStrLength(b) - getStrLength(a)})[0]) | |||
for(var i in options){ | |||
var minus = maxOptionLen - getStrLength(options[i]) | |||
for(var n=0;n<minus;n++){ | |||
options[i] += ' ' | |||
} | |||
} | |||
// console.log(options) | |||
return sortDicByKey(options) //返回一个 Map 对象 | |||
} | |||
function newTimu(id,json, settings){ | function newTimu(id,json, settings){ | ||
settings = json.settings===undefined||json.isA3 ? settings:json.settings//检测json是否带有settings或者是否为A3子题目 | settings = json.settings===undefined||json.isA3 ? settings:json.settings//检测json是否带有settings或者是否为A3子题目 | ||
第257行: | 第282行: | ||
o.title = json.title | o.title = json.title | ||
o.options = json.choices | o.options = json.choices | ||
console.log(o.options) | // console.log(o.options) | ||
//将choice 统一为Array的转换为obj | //将choice 统一为Array的转换为obj | ||
if(typeOfObj(o.options)==='[object Array]'&&o.options.length===1&&o.type!=='A3'){ | if(typeOfObj(o.options)==='[object Array]'&&o.options.length===1&&o.type!=='A3'){ | ||
o.options = o.options[0] | o.options = o.options[0] | ||
} | } | ||
o.options = o.options!==undefined? | o.options = o.options!==undefined? cleanAndMakeSameLenOptions(o.options):'' | ||
console.log(o.options) | // console.log(o.options) | ||
o.answer = json.answer | o.answer = json.answer | ||
第270行: | 第295行: | ||
o.temp = { | o.temp = { | ||
main:$('<div name="timu-'+(id+1)+'" id="'+id+'" class="type'+o.type+' timuContainer"><p class="timuID">'+id+'</p></div>'), | main:$('<div name="timu-'+(id+1)+'" id="'+id+'" class="type'+o.type+' timuContainer"><p class="timuID">'+id+'</p></div>'), | ||
} | } | ||
第299行: | 第309行: | ||
o.A = function () { | o.A = function () { | ||
//subjectForm | //subjectForm | ||
this.type = json.isA3?'A3':'A' | |||
var optionsGroupObj = optionsGroup(this.type, id, this.options) | var optionsGroupObj = optionsGroup(this.type, id, this.options) | ||
if(json.isA3){ | if(json.isA3){ | ||
第307行: | 第318行: | ||
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):'' | var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):'' | ||
var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj | var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj]) | ||
//resultGroupObj | //resultGroupObj | ||
var answerInlineObj = answerInline(this.answer) | var answerInlineObj = answerInline(this.answer) | ||
第313行: | 第324行: | ||
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | ||
this.temp.main.append(subjectForm,resultGroupObj) | this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj ) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
第323行: | 第334行: | ||
var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline') | var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline') | ||
var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main) | var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main) | ||
var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj | var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj]) | ||
//resultGroupObj | //resultGroupObj | ||
var answerInlineObj = answerInline(this.answer) | var answerInlineObj = answerInline(this.answer) | ||
第329行: | 第340行: | ||
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | ||
this.temp.main.append(subjectForm,resultGroupObj) | this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj ) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
第335行: | 第346行: | ||
} | } | ||
o.A3 = function () { | o.A3 = function () { | ||
console.log(settings) | // console.log(settings) | ||
var realSource = getRealSource(json.source) | var realSource = getRealSource(json.source) | ||
var sourcePrefix = realSource.prefix===''?'':realSource.prefix | var sourcePrefix = realSource.prefix===''?'':realSource.prefix | ||
第356行: | 第367行: | ||
"choices":this.options.get(i+''), | "choices":this.options.get(i+''), | ||
} | } | ||
console.log(data) | // console.log(data) | ||
console.log(this.options) | // console.log(this.options) | ||
subTitlesList.push(newTimu(id+'-'+i,data,{ | subTitlesList.push(newTimu(id+'-'+i,data,{ | ||
showHr:false, | showHr:false, | ||
第366行: | 第377行: | ||
} | } | ||
console.log(this.answer) | // console.log(this.answer) | ||
var buttonGroupObj = buttonGroup(true, false, id, this.type, this.answer, this.temp.main) | var buttonGroupObj = buttonGroup(true, false, id, this.type, this.answer, this.temp.main) | ||
console.log(buttonGroupObj) | // console.log(buttonGroupObj) | ||
var subjectFormObj = | var subjectFormObj = subjectDIV(id,this.type, [subTitlesList]) | ||
this.temp.main.append(range,info, subjectFormObj) | this.temp.main.append(range,info, subjectFormObj, buttonGroupObj) | ||
this.temp.main.append('<hr>') | this.temp.main.append('<hr>') | ||
第391行: | 第402行: | ||
var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main) | var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main) | ||
var subjectForm = subjectFrom(id, [optionsGroupObj, titlesGroupObj | var subjectForm = subjectFrom(id,this.type, [optionsGroupObj, titlesGroupObj]) | ||
//resultGroupObj | //resultGroupObj | ||
第406行: | 第417行: | ||
var resultGroupObj = resultGroup(id, resultGroupList) | var resultGroupObj = resultGroup(id, resultGroupList) | ||
this.temp.main.append(range ,subjectForm,resultGroupObj) | this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
第427行: | 第438行: | ||
var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main) | var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main) | ||
var subjectForm = subjectFrom(id, [titlesGroupObj, optionsGroupObj | var subjectForm = subjectFrom(id,this.type, [titlesGroupObj, optionsGroupObj]) | ||
//resultGroupObj | //resultGroupObj | ||
第442行: | 第453行: | ||
var resultGroupObj = resultGroup(id, resultGroupList) | var resultGroupObj = resultGroup(id, resultGroupList) | ||
this.temp.main.append(range ,subjectForm,resultGroupObj) | this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
第452行: | 第463行: | ||
var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline') | var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline') | ||
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):'' | var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):'' | ||
var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj | var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj]) | ||
//resultGroupObj | //resultGroupObj | ||
var answerInlineObj = answerInline(this.answer) | var answerInlineObj = answerInline(this.answer) | ||
第458行: | 第469行: | ||
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | ||
this.temp.main.append(subjectForm,resultGroupObj) | this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj ) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
第468行: | 第479行: | ||
wrong: ['错', '错误', '×', 'x', 'f', 'false', 'wrong', '0'] | wrong: ['错', '错误', '×', 'x', 'f', 'false', 'wrong', '0'] | ||
} | } | ||
var ans = '' | var ans = '' | ||
var ansOption = '' | var ansOption = '' | ||
第491行: | 第498行: | ||
var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline') | var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline') | ||
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, 'A', ansOption, this.temp.main):'' | var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, 'A', ansOption, this.temp.main):'' | ||
var subjectForm = subjectFrom(id, [titleInlineObj, optionsGroupObj | var subjectForm = subjectFrom(id,this.type, [titleInlineObj,optionsGroupObj]) | ||
//resultGroupObj | //resultGroupObj | ||
var answerInlineObj = answerInline(ans) | var answerInlineObj = answerInline(ans) | ||
第497行: | 第504行: | ||
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj]) | ||
this.temp.main.append(subjectForm,resultGroupObj) | this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj ) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
第503行: | 第510行: | ||
} | } | ||
o.TK = function () { | o.TK = function () { | ||
var tkTitle = fillBlank(id, this.title, this.pos, [' | var tkTitle = fillBlank(id, this.title, this.pos, ['text-input-tk']) | ||
var titleInlineObj = titleInline(id, this.type,this.source,undefined,tkTitle, 'titleInline-no-flex') | var titleInlineObj = titleInline(id, this.type,this.source,undefined,tkTitle, 'titleInline-no-flex') | ||
titleInlineObj.children('. | titleInlineObj.children('.text-input-tk').each(function(i,v){ | ||
console.log(i,v) | // console.log(i,v) | ||
$(this).children('input').css( | $(this).children('input').css( | ||
'display','inline' | 'display','inline' | ||
第515行: | 第522行: | ||
}) | }) | ||
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):'' | var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):'' | ||
var subjectForm = subjectFrom(id, [titleInlineObj | var subjectForm = subjectFrom(id,this.type, [titleInlineObj]) | ||
this.temp.main.append(subjectForm) | this.temp.main.append(subjectForm, buttonGroupObj) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
第527行: | 第534行: | ||
mjTitle = json.title + ':<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>' | mjTitle = json.title + ':<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>' | ||
}else{ | }else{ | ||
mjTitle = fillBlank(id, this.title+':()', '()', [' | mjTitle = fillBlank(id, this.title+':()', '()', ['text-input-mj']) | ||
} | } | ||
var titleInlineObj = titleInline(id, this.type,this.source,undefined,mjTitle, 'titleInline-no-flex') | var titleInlineObj = titleInline(id, this.type,this.source,undefined,mjTitle, 'titleInline-no-flex') | ||
titleInlineObj.children('. | titleInlineObj.children('.text-input-mj').each(function(i,v){ | ||
console.log(i,v) | // console.log(i,v) | ||
$(this).children('input').css( | $(this).children('input').css( | ||
'display','inline' | 'display','inline' | ||
第540行: | 第547行: | ||
}) | }) | ||
var buttonGroupObj = this.inputBox!==0 ? buttonGroup(showSubmitBtn, showEditBtn, id, 'TK', [this.answer], this.temp.main):'' | var buttonGroupObj = this.inputBox!==0 ? buttonGroup(showSubmitBtn, showEditBtn, id, 'TK', [this.answer], this.temp.main):'' | ||
var subjectForm = subjectFrom(id, [titleInlineObj | var subjectForm = subjectFrom(id,this.type, [titleInlineObj]) | ||
this.temp.main.append(subjectForm) | this.temp.main.append(subjectForm, buttonGroupObj) | ||
if(showHr){this.temp.main.append('<hr>')} | if(showHr){this.temp.main.append('<hr>')} | ||
return this.temp.main | return this.temp.main | ||
第549行: | 第556行: | ||
} | } | ||
// // 获取select的选项 | |||
function getSelectedAnswer(id){ | function getSelectedAnswer(id){ | ||
var data = formToJSON('# | var data = formToJSON('#'+prefixDic.formId + id,true) | ||
console.log(data) | |||
return data | return data | ||
} | |||
// // 获取checkbox值 | |||
function getCheckBoxValue(name) { | |||
var ids = $('input:checkbox[name="'+name+'"]:checked'); | |||
var data = []; | |||
for (var i = 0; i < ids.length; i ++) { | |||
data.push(ids[i].value) | |||
} | |||
return data | |||
} | } | ||
function showThisAnswer(id,type,correctAnswer){ | function showThisAnswer(id,type,correctAnswer){ | ||
var isRight = false | |||
var resultGroup = $('#resultGroup-'+id) | var resultGroup = $('#resultGroup-'+id) | ||
resultGroup.fadeIn(100) | resultGroup.fadeIn(100) | ||
$('#showThisAnswer-'+id).fadeOut(1) | $('#showThisAnswer-'+id).fadeOut(1) | ||
if(type==="A" || type ==='A2'){ | if(type==="A" || type ==='A2'){ | ||
var | var optionGroupName = prefixDic.radioName+id | ||
var optionInlinePrefixID = | var optionInlinePrefixID = prefixDic.radioName+id | ||
var usersChoice = getSelectedAnswer(id)[ | var usersChoice = getSelectedAnswer(id)[optionGroupName] | ||
console.log(usersChoice) | |||
var correctDivObj = $('#'+optionInlinePrefixID + '-' + correctAnswer) | var correctDivObj = $('#'+optionInlinePrefixID + '-' + correctAnswer) | ||
var usersChoiceDivObj = $('#'+optionInlinePrefixID + '-' + usersChoice) | var usersChoiceDivObj = $('#'+optionInlinePrefixID + '-' + usersChoice) | ||
第572行: | 第587行: | ||
if(usersChoice===correctAnswer){ | if(usersChoice===correctAnswer){ | ||
correctDivObj.addClass('correct') | correctDivObj.addClass('correct') | ||
isRight = true | |||
}else{ | }else{ | ||
correctDivObj.addClass('correct') | correctDivObj.addClass('correct') | ||
第583行: | 第599行: | ||
} | } | ||
} else if(type==='B'){ | } else if(type==='B'){ | ||
var dropDownInputPrefix = ' | var dropDownInputPrefix = 'select-'+id +'-' | ||
var usersChoice = getSelectedAnswer(id) | var usersChoice = getSelectedAnswer(id) | ||
console.log(usersChoice) | // console.log(usersChoice) | ||
for(var i in usersChoice){ | for(var i in usersChoice){ | ||
第602行: | 第618行: | ||
} | } | ||
} else if(type=="C"){ | } else if(type=="C"){ | ||
var dropDownInputPrefix = ' | var dropDownInputPrefix = 'select-'+id +'-' | ||
var usersChoice = getSelectedAnswer(id) | var usersChoice = getSelectedAnswer(id) | ||
console.log(usersChoice) | // console.log(usersChoice) | ||
for(var i in usersChoice){ | for(var i in usersChoice){ | ||
第621行: | 第637行: | ||
} | } | ||
}else if(type=="X"){ | }else if(type=="X"){ | ||
var | var optionGroupName = 'checkbox-'+id | ||
var optionInlinePrefixID = ' | var optionInlinePrefixID = 'checkbox-'+id | ||
var usersChoice = getCheckBoxValue( | var usersChoice = getCheckBoxValue(optionGroupName).sort() | ||
correctAnswer = correctAnswer.match(/[A-Z]/g).sort() | correctAnswer = correctAnswer.match(/[A-Z]/g).sort() | ||
var lenCorrect = correctAnswer.length | var lenCorrect = correctAnswer.length | ||
var lenUser = usersChoice.length | var lenUser = usersChoice.length | ||
console.log(correctAnswer) | // console.log(correctAnswer) | ||
for(var i=0;i<lenUser;i++){ | for(var i=0;i<lenUser;i++){ | ||
console.log(isInArray(correctAnswer, usersChoice[i]),usersChoice[i] ,correctAnswer) | // console.log(isInArray(correctAnswer, usersChoice[i]),usersChoice[i] ,correctAnswer) | ||
if(!isInArray(correctAnswer, usersChoice[i])){ | if(!isInArray(correctAnswer, usersChoice[i])){ | ||
$('#'+optionInlinePrefixID + '-' + usersChoice[i]).addClass('wrong') | $('#'+optionInlinePrefixID + '-' + usersChoice[i]).addClass('wrong') | ||
第645行: | 第661行: | ||
}else if(type=="TK"){ | }else if(type=="TK"){ | ||
var textInputPrefix = | var textInputPrefix = prefixDic.textInputId+id+'-' | ||
var usersChoice = getSelectedAnswer(id) | var usersChoice = getSelectedAnswer(id) | ||
for(var i in usersChoice){ | for(var i in usersChoice){ | ||
var inputID = i.replace(textInputPrefix,'') | var inputID = i.replace(textInputPrefix,'') | ||
console.log('#'+i) | // console.log('#'+i) | ||
var corrcetAnswerText = correctAnswer[inputID]===undefined?'暂无答案':correctAnswer[inputID] | var corrcetAnswerText = correctAnswer[inputID]===undefined?'暂无答案':correctAnswer[inputID] | ||
if(usersChoice[i]===correctAnswer[inputID]){ | if(usersChoice[i]===correctAnswer[inputID]){ | ||
第657行: | 第673行: | ||
} | } | ||
} | } | ||
} | |||
if(isRight){ | |||
locateTo(id+1) | |||
} | } | ||
} | } | ||
function removeBackground(obj){ | function removeBackground(obj){ | ||
obj.addClass('no-background') | obj.addClass('no-background') | ||
} | } |
2023年6月29日 (四) 15:04的最新版本
//设置
var prefixDic = {
formId:'timuForm-',
radioName:'radio-',
radioId:'radio-input-',
checkBoxName:'checkbox-',
checkBoxId:'checkbox-input-',
selectId:'select-',
selectName:'select-',
textInputName:'text-',
textInputId:'text-'
}
//主函数
function renderTimuFromSessionStorage(){
var timuList = gDomTimuList()
// console.log(timuList)
var order = timuList.order
var timu = timuList.timu
var errors = timuList.errors
var repeatSource = timuList.repeatSource
for(var i=0;i<order.length;i++){
if(order[i].isError){
var errorWidget = new OO.ui.MessageWidget( {
type: 'error',
showClose:true,
label: 'id='+i+'的题目加载错误,错误信息:'+errors[i].info.name+':'+errors[i].info.message+'\n'+'对应文本:'+errors[i].dataText
} )
render(i,'A',$('<di></div>').append(errorWidget.$element,'<hr>'))
}else{
var dataJSON = timu[i].dataJSON
var o = newTimu(i,dataJSON,{})[dataJSON.type]()
render(i,dataJSON.type,o)
var needCheck = $('#noRepeatCheck').length<=0
if(repeatSource[i]!==undefined&&needCheck){
var warningWidget = new OO.ui.MessageWidget( {
type: 'warning',
label: '本题与本页面id为'+repeatSource[i]+'的题目source参数重复,本参数重复可能引起错误,请检查并修改!'
} )
render(i,'A',warningWidget.$element)
}
}
}
}
//题目渲染函数
//生成info
function infoInline(info){
return $('<div class="info">'+info+'</div>')
}
//单行题干的处理titleInline(type, source, title)
//生成titleGroup
function titlesGroup(titlesList){
var group = $('<div class="titlesGroup"></div>')
for(var i=0;i<titlesList.length;i++){
group.append(titlesList[i])
}
return group
}
//生成titleInline
function titleInline(id, type,originalSource, sourceSuffix,title, classes){
classes = classes===undefined?'':classes
return $('<div id="title-'+id+'" class="'+classes+'"></div>').append(
titleInlineType(type),
titleInlineSource(originalSource,sourceSuffix,type),
titleInlineTitle(title)
)
}
function titleInlineType(type){
var typeChinese = {
A:'A',
A2:'A2',
A3:'A3',
B:'B',
C:'C',
X:'X',
TK:'填空',
PD:'判断',
MJ:'名解'
}
return $('<p class="type">'+typeChinese[type]+'</p>')
}
//从有中文的source中提取最后一个连续数字作为真实的source
function getRealSource(source){
// console.log(source)
var getContinueNumber = source.match(/[0-9]+/g)
var splitContinueNumber = source.split(/[0-9]+/g)
var realSource = getContinueNumber[getContinueNumber.length-1]*1
var prefix = ''
for(var i=0;i<getContinueNumber.length;i++){
prefix += splitContinueNumber[i]
}
return {prefix:prefix,source:realSource}
}
//返回source的obj
function titleInlineSource(originalSource, suffix , type){
var realSource = type==='A3'?{prefix:'', source:originalSource}: getRealSource(originalSource)
var prefix = realSource.prefix
var source = realSource.source
var suffix = suffix === undefined ? '':'-'+suffix
return $('<p class="source">'+prefix+source+suffix+'</p>')
}
//返回sourceRange的obj
function rangeInline(originalSource, sourceRange, type){
var source = getRealSource(originalSource).source
var end = source*1+sourceRange*1 -1
var rangeText = '第 '+source +' 到 ' + end + ' 题'
var suffix = type==='B'?'共用备选答案':'共用题干'
return $('<div class="sourceRange">'+rangeText + suffix +'</div>')
}
//返回title 的 obj
function titleInlineTitle(title){
return $('<p class="title">'+title+'</p>')
}
//生成buttonGroup
function buttonGroup(showSubmitBtn, showEditBtn, id, type, correctAnswer, hoverTarget){
// console.log(showEditBtn)
var buttonGroupObj = $('<div class="buttonGroup"></div>')
if(showSubmitBtn){buttonGroupObj.append(
new OO.ui.ButtonWidget( {
id:'showThisAnswer-'+id,
label: '提交',
flags: [
'progressive'
]
} ).$element.bind("click",function (){
showThisAnswer(id,type,correctAnswer)
})
)}
if(showEditBtn){
buttonGroupObj.append(
// $('<a class="editThisBtn" style="" href="javascript:void(0)"><span class="" id="editThis-' + id + '">题目有误?点击编辑本题</span></a>'),
new OO.ui.ButtonWidget( {
id:'editThis-' + id,
classes:['editThisBtn'],
framed: false,
flags: [
'progressive'
],
icon: 'edit',
label: '题目有误?点击编辑本题'
} ).$element.bind("click",function (){
editThis(id)
})
)
hoverTarget.hover(function () {
buttonGroupObj.children('.editThisBtn').fadeIn(10)
},function (){
buttonGroupObj.children('.editThisBtn').fadeOut(70)
})
}
return buttonGroupObj
}
//resultGroup: answer和explain的显示框
function resultGroup(id, items, answerInline,explainInline){
var group = $('<div id="resultGroup-'+id+'" class="resultGroup"></div>')
for(var i=0;i<items.length;i++){
group.append(items[i])
}
return group
}
//生成answerInline
function answerInline(answer){
return $('<div class="answerInline"><label>正确答案:</label>'+answer+'</div>')
}
//生成explainInline
function explainInline(explain){
return $('<div class="explainInline"><label>解析:</label>'+explain+'</div>')
}
//生成subject 的form, 顺序items顺序添加 (title, options, buttonGroup)
function subjectFrom(id, type, items){
var form = $('<form id="'+prefixDic.formId+id+'" class="subjectForm"></form>')
//绑定变化事件
form.change(function(){
// 如果开启了暂存,则暂存
if(!gWebPageTimuSettings().noTemp){
formChangeListener(id, type)
}
})
for(var i=0;i<items.length;i++){
form.append(items[i])
}
return form
}
function subjectDIV(id,type,items){
var div= $('<div id="'+prefixDic.formId+id+'" class="subjectForm"></div>')
for(var i=0;i<items.length;i++){
div.append(items[i])
}
return div
}
//生成填空输入框
function fillBlank(id, title, pos, classes){
// console.log(pos)
var posReg = new RegExp(pos,'g')
var blankLen = title.match(posReg).length
var split = title.split(posReg)
// console.log(blankLen)
var newTitle = ''
for(var i=0;i<(blankLen+split.length);i++){
if(i%2===0){
newTitle += '<p class="title">'+split[Math.floor(i/2)]+'</div>'
}else{
newTitle += new OO.ui.TextInputWidget( {
name:prefixDic.textInputName+id+'-'+Math.floor(i/2),
id:prefixDic.textInputId+id+'-'+Math.floor(i/2),
classes:classes
} ).$element.prop('outerHTML')
}
}
return newTitle
}
//生成B、C型题的选择框
function dropDownInputWidget(id, availabelOptions){
var options = []
var select = $('<select class="dorpdown" id="'+prefixDic.selectId+id+'" name="'+prefixDic.selectName+id+'"></select>')
for(var i=0;i<availabelOptions.length;i++){
select.append('<option class="dropdown-option" value="'+availabelOptions[i]+'">'+availabelOptions[i]+'</option>')
}
return select
}
//生成options(options 是 Map对象)
function optionsGroup(type,id,options){
var flexClass = (type==='B')||(type==='C') ? 'optionsGroup-flex':''
var inputType = type==='X' ? 'checkbox':'radio'
var optionGroupObj = $('<div class="optionsGroup '+flexClass+'"></div>')
options.forEach(function(value, key, map){
optionGroupObj.append(optionInline(id, key, value, !((type==='B')||(type==='C')), inputType))
})
return optionGroupObj
}
//生成optionInline
function optionInline(id, option, content,input,inputType){
var idPrefix = inputType === 'checkbox' ? prefixDic.checkBoxId:prefixDic.radioId
var namePrefix = inputType === 'checkbox' ? prefixDic.checkBoxName:prefixDic.radioName // 这个和外部的div的id一样就共用了
var input = input ? $('<input id="'+ idPrefix + id+'-'+option+'" name="'+ namePrefix + id + '" type="'+inputType+'" value="' + option + '" />'):''
var optionLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+option+'. </label>')
var contentLabel = $('<label for="'+ idPrefix + id+'-'+option+'">'+content+'</label>')
return $('<div id="'+ namePrefix +id+'-'+option+'" class="optionInline"></div>').append(input,optionLabel,contentLabel)
}
//清理json中的choice(清除空项并排序),接收Obj,
function cleanAndMakeSameLenOptions(options){
//清除空项
var options = filterEmptyEntries(options)
//让所有option长度一样
var maxOptionLen = getStrLength(Object.values(options).sort(function(a,b){return getStrLength(b) - getStrLength(a)})[0])
for(var i in options){
var minus = maxOptionLen - getStrLength(options[i])
for(var n=0;n<minus;n++){
options[i] += ' '
}
}
// console.log(options)
return sortDicByKey(options) //返回一个 Map 对象
}
function newTimu(id,json, settings){
settings = json.settings===undefined||json.isA3 ? settings:json.settings//检测json是否带有settings或者是否为A3子题目
parent = settings.parent === undefined ? '' : settings.parent
showHr = settings.showHr == undefined ? true : settings.showHr
showSubmitBtn = settings.showSubmitBtn === undefined ? true : settings.showSubmitBtn
showEditBtn = settings.showEditBtn === undefined ? true : settings.showEditBtn
showBtnGroup = settings.showBtnGroup === undefined? true:settings.showBtnGroup
var o = new Object()
o.type = json.type
o.pos = json.pos
o.inputBox = json.inputBox
o.source = json.source
o.sourceRange = json.sourceRange
o.info = json.info
o.title = json.title
o.options = json.choices
// console.log(o.options)
//将choice 统一为Array的转换为obj
if(typeOfObj(o.options)==='[object Array]'&&o.options.length===1&&o.type!=='A3'){
o.options = o.options[0]
}
o.options = o.options!==undefined? cleanAndMakeSameLenOptions(o.options):''
// console.log(o.options)
o.answer = json.answer
o.explain = json.explain
o.temp = {
main:$('<div name="timu-'+(id+1)+'" id="'+id+'" class="type'+o.type+' timuContainer"><p class="timuID">'+id+'</p></div>'),
}
o.parent = parent
// if(this.type==='A3'){
// $(this).children('.subject').children('.editThisButton').fadeIn(1)
// }
o.temp.main.hover(function () {
$('editThis-' + id).fadeIn(10)
},function (){
$('editThis-' + id).fadeOut(70)
})
o.A = function () {
//subjectForm
this.type = json.isA3?'A3':'A'
var optionsGroupObj = optionsGroup(this.type, id, this.options)
if(json.isA3){
var titleInlineObj = titleInline(id, 'A3',this.source,undefined,this.title,'titleInline')
}else{
var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
}
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
//resultGroupObj
var answerInlineObj = answerInline(this.answer)
var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
o.A2 = function () {
//subjectForm
var optionsGroupObj = optionsGroup(this.type, id, this.options)
var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
//resultGroupObj
var answerInlineObj = answerInline(this.answer)
var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
o.A3 = function () {
// console.log(settings)
var realSource = getRealSource(json.source)
var sourcePrefix = realSource.prefix===''?'':realSource.prefix
//subjectForm
var range = rangeInline(this.source, this.sourceRange)
var info = infoInline(this.info)
var subTitlesList = []
for(var i=0;i<this.title.length;i++){
if(this.explain[i]==undefined){
this.explain[i] = '暂无解析'
}
var data = {
'isA3':true,
"type":"A",
"source":sourcePrefix+realSource.source+'-'+(i+1),
"title":this.title[i],
"answer":this.answer[i],
"explain":this.explain[i],
"choices":this.options.get(i+''),
}
// console.log(data)
// console.log(this.options)
subTitlesList.push(newTimu(id+'-'+i,data,{
showHr:false,
showEditBtn:false,
showSubmitBtn:false,
showBtnGroup:false
}).A())
}
// console.log(this.answer)
var buttonGroupObj = buttonGroup(true, false, id, this.type, this.answer, this.temp.main)
// console.log(buttonGroupObj)
var subjectFormObj = subjectDIV(id,this.type, [subTitlesList])
this.temp.main.append(range,info, subjectFormObj, buttonGroupObj)
this.temp.main.append('<hr>')
return this.temp.main
}
o.B = function () {
var realSource = getRealSource(json.source)
var sourcePrefix = realSource.prefix===''?'':realSource.prefix
//subjectForm
var range = rangeInline(this.source, this.sourceRange)
var optionsGroupObj = optionsGroup(this.type, id, this.options)
var titleInlineList = []
for(var i=0;i<this.title.length;i++){
var dropdown = dropDownInputWidget(id+'-'+i, mapKeysList(this.options))
var titleInlineObj = titleInline(id+'-'+i, this.type, json.source, i, this.title[i],'titleInline')
titleInlineObj.append(dropdown)
titleInlineList.push(titleInlineObj)
}
var titlesGroupObj = titlesGroup(titleInlineList)
var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
var subjectForm = subjectFrom(id,this.type, [optionsGroupObj, titlesGroupObj])
//resultGroupObj
var resultGroupList = []
for(var i=0;i<this.answer.length;i++){
var answerInlineObj = answerInline(this.answer[i])
var explainInlineObj = this.explain[i] === undefined || this.explain[i] === '' ? '暂无解析' : explainInline(this.explain[i])
resultGroupList.push(
'<b>'+sourcePrefix+realSource.source+'-'+i+'</b>',
$('<div style="margin-left:10px"></div>').append(answerInlineObj),
$('<div style="margin-left:10px"></div>').append(explainInlineObj)
)
}
var resultGroupObj = resultGroup(id, resultGroupList)
this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj)
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
o.C = function () {
var realSource = getRealSource(json.source)
var sourcePrefix = realSource.prefix===''?'':realSource.prefix
//subjectForm
var range = rangeInline(this.source, this.sourceRange)
var optionsGroupObj = optionsGroup(this.type, id, this.options)
var titleInlineList = []
for(var i=0;i<this.title.length;i++){
var dropdown = dropDownInputWidget(id+'-'+i, mapKeysList(this.options))
var titleInlineObj = titleInline(id+'-'+i, this.type, json.source, i, this.title[i],'titleInline')
titleInlineObj.append(dropdown)
titleInlineList.push(titleInlineObj)
}
var titlesGroupObj = titlesGroup(titleInlineList)
var buttonGroupObj = buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main)
var subjectForm = subjectFrom(id,this.type, [titlesGroupObj, optionsGroupObj])
//resultGroupObj
var resultGroupList = []
for(var i=0;i<this.answer.length;i++){
var answerInlineObj = answerInline(this.answer[i])
var explainInlineObj = this.explain[i] === undefined || this.explain[i] === '' ? '暂无解析' : explainInline(this.explain[i])
resultGroupList.push(
'<b>'+sourcePrefix+realSource.source+'-'+i+'</b>',
$('<div style="margin-left:10px"></div>').append(answerInlineObj),
$('<div style="margin-left:10px"></div>').append(explainInlineObj)
)
}
var resultGroupObj = resultGroup(id, resultGroupList)
this.temp.main.append(range ,subjectForm,resultGroupObj, buttonGroupObj)
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
o.X = function () {
//subjectForm
var optionsGroupObj = optionsGroup(this.type, id, this.options)
var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
var subjectForm = subjectFrom(id,this.type, [titleInlineObj, optionsGroupObj])
//resultGroupObj
var answerInlineObj = answerInline(this.answer)
var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
o.PD = function () {
var dic = {
right: ['对', '正确', 't', '✓', '√', '1', 'true'],
wrong: ['错', '错误', '×', 'x', 'f', 'false', 'wrong', '0']
}
var ans = ''
var ansOption = ''
if(isInArray(dic.right, json.answer.toLowerCase())){
ans = '正确'
ansOption = 'A'
}else if(isInArray(dic.wrong, json.answer.toLowerCase())){
ans = '错误'
ansOption = 'B'
}else {
ans = '系统错误:该判断题答案不符合标准格式'
}
//subjectForm
var option = new Map()
option.set('A', '正确')
option.set('B', '错误')
var optionsGroupObj = optionsGroup(this.type, id, option)
var titleInlineObj = titleInline(id, this.type,this.source,undefined,this.title,'titleInline')
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, 'A', ansOption, this.temp.main):''
var subjectForm = subjectFrom(id,this.type, [titleInlineObj,optionsGroupObj])
//resultGroupObj
var answerInlineObj = answerInline(ans)
var explainInlineObj = this.explain === undefined || this.explain === '' ? '暂无解析' : explainInline(this.explain)
var resultGroupObj = resultGroup(id, [answerInlineObj, explainInlineObj])
this.temp.main.append(subjectForm,resultGroupObj,buttonGroupObj )
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
o.TK = function () {
var tkTitle = fillBlank(id, this.title, this.pos, ['text-input-tk'])
var titleInlineObj = titleInline(id, this.type,this.source,undefined,tkTitle, 'titleInline-no-flex')
titleInlineObj.children('.text-input-tk').each(function(i,v){
// console.log(i,v)
$(this).children('input').css(
'display','inline'
)
$(this).children('input').css(
'width','200px'
)
})
var buttonGroupObj = showBtnGroup? buttonGroup(showSubmitBtn, showEditBtn, id, this.type, this.answer, this.temp.main):''
var subjectForm = subjectFrom(id,this.type, [titleInlineObj])
this.temp.main.append(subjectForm, buttonGroupObj)
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
o.MJ = function () {
var mjTitle = ''
if(this.inputBox===0){
mjTitle = json.title + ':<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>'
}else{
mjTitle = fillBlank(id, this.title+':()', '()', ['text-input-mj'])
}
var titleInlineObj = titleInline(id, this.type,this.source,undefined,mjTitle, 'titleInline-no-flex')
titleInlineObj.children('.text-input-mj').each(function(i,v){
// console.log(i,v)
$(this).children('input').css(
'display','inline'
)
$(this).children('input').css(
'width','auto'
)
})
var buttonGroupObj = this.inputBox!==0 ? buttonGroup(showSubmitBtn, showEditBtn, id, 'TK', [this.answer], this.temp.main):''
var subjectForm = subjectFrom(id,this.type, [titleInlineObj])
this.temp.main.append(subjectForm, buttonGroupObj)
if(showHr){this.temp.main.append('<hr>')}
return this.temp.main
}
return o
}
// // 获取select的选项
function getSelectedAnswer(id){
var data = formToJSON('#'+prefixDic.formId + id,true)
console.log(data)
return data
}
// // 获取checkbox值
function getCheckBoxValue(name) {
var ids = $('input:checkbox[name="'+name+'"]:checked');
var data = [];
for (var i = 0; i < ids.length; i ++) {
data.push(ids[i].value)
}
return data
}
function showThisAnswer(id,type,correctAnswer){
var isRight = false
var resultGroup = $('#resultGroup-'+id)
resultGroup.fadeIn(100)
$('#showThisAnswer-'+id).fadeOut(1)
if(type==="A" || type ==='A2'){
var optionGroupName = prefixDic.radioName+id
var optionInlinePrefixID = prefixDic.radioName+id
var usersChoice = getSelectedAnswer(id)[optionGroupName]
console.log(usersChoice)
var correctDivObj = $('#'+optionInlinePrefixID + '-' + correctAnswer)
var usersChoiceDivObj = $('#'+optionInlinePrefixID + '-' + usersChoice)
if(usersChoice===correctAnswer){
correctDivObj.addClass('correct')
isRight = true
}else{
correctDivObj.addClass('correct')
usersChoiceDivObj.addClass('wrong')
}
}else if(type==='A3'){
for(var i=0;i<correctAnswer.length;i++){
//以下与A型题时一样的代码,知识用subID替换ID变量
showThisAnswer(id+'-'+i,'A',correctAnswer[i])
}
} else if(type==='B'){
var dropDownInputPrefix = 'select-'+id +'-'
var usersChoice = getSelectedAnswer(id)
// console.log(usersChoice)
for(var i in usersChoice){
var dorpdownID = i.replace(dropDownInputPrefix,'')//获取子ID
var subTimuID = id+'-'+dorpdownID
var thisTimuUsersChoice = usersChoice[i]
var thisTimuCorrectAnswer = correctAnswer[dorpdownID]
var subTimuDiv = $('#title-'+subTimuID)
if(thisTimuUsersChoice===thisTimuCorrectAnswer){
subTimuDiv.addClass('correct')
}else{
subTimuDiv.addClass('wrong')
subTimuDiv.append('<label class="answerTip">正确答案:'+thisTimuCorrectAnswer+'</label>')
}
}
} else if(type=="C"){
var dropDownInputPrefix = 'select-'+id +'-'
var usersChoice = getSelectedAnswer(id)
// console.log(usersChoice)
for(var i in usersChoice){
var dorpdownID = i.replace(dropDownInputPrefix,'')//获取子ID
var subTimuID = id+'-'+dorpdownID
var thisTimuUsersChoice = usersChoice[i]
var thisTimuCorrectAnswer = correctAnswer[dorpdownID]
var subTimuDiv = $('#title-'+subTimuID)
if(thisTimuUsersChoice===thisTimuCorrectAnswer){
subTimuDiv.addClass('correct')
}else{
subTimuDiv.addClass('wrong')
subTimuDiv.append('<label class="answerTip">正确答案:'+thisTimuCorrectAnswer+'</label>')
}
}
}else if(type=="X"){
var optionGroupName = 'checkbox-'+id
var optionInlinePrefixID = 'checkbox-'+id
var usersChoice = getCheckBoxValue(optionGroupName).sort()
correctAnswer = correctAnswer.match(/[A-Z]/g).sort()
var lenCorrect = correctAnswer.length
var lenUser = usersChoice.length
// console.log(correctAnswer)
for(var i=0;i<lenUser;i++){
// console.log(isInArray(correctAnswer, usersChoice[i]),usersChoice[i] ,correctAnswer)
if(!isInArray(correctAnswer, usersChoice[i])){
$('#'+optionInlinePrefixID + '-' + usersChoice[i]).addClass('wrong')
}
}
for(var i=0;i<lenCorrect;i++){
if(!isInArray(usersChoice,correctAnswer[i])){
$('#'+optionInlinePrefixID + '-' + correctAnswer[i]).addClass('notChoiced')
}else {
$('#'+optionInlinePrefixID + '-' + correctAnswer[i]).addClass('correct')
}
}
}else if(type=="TK"){
var textInputPrefix = prefixDic.textInputId+id+'-'
var usersChoice = getSelectedAnswer(id)
for(var i in usersChoice){
var inputID = i.replace(textInputPrefix,'')
// console.log('#'+i)
var corrcetAnswerText = correctAnswer[inputID]===undefined?'暂无答案':correctAnswer[inputID]
if(usersChoice[i]===correctAnswer[inputID]){
$('#'+i).html('<label class="answerTip correct">'+corrcetAnswerText+'</label>')
}else{
$('#'+i).after('<label class="answerTip wrong">'+corrcetAnswerText+'</label>')
}
}
}
if(isRight){
locateTo(id+1)
}
}
function removeBackground(obj){
obj.addClass('no-background')
}