打开/关闭菜单
Toggle preferences menu
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Gadget-tikuRenderModule.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第1行: 第1行:
function getdata(){
function getdata(){
            var data = $('.data')
    var data = $('.data')
            var dataLength = data.length
    var dataLength = data.length
             var subjectCon = $('.subjectContainer')
    for(var i=0;i<dataLength;i++){
            console.log(data)
        var singleData = $(data[i]).text()
            $('<button class="button" id="typeAReset">重置答题状态</button>').prependTo($('#subjectContainer-A'))
        var jsonData = $.parseJSON(singleData)
            $('<button class="button" id="typeBReset">重置答题状态</button>').prependTo($('#subjectContainer-B'))
        setTimeout(function(jsonData,i,dataLength){
            $('<button class="button" id="typeCReset">重置答题状态</button>').prependTo($('#subjectContainer-C'))
            var o = eval('newTimu('+i+','+JSON.stringify(jsonData)+').'+jsonData.type+'()')
            $('<button class="button" id="typeXReset">重置答题状态</button>').prependTo($('#subjectContainer-X'))
            render(i,jsonData.type,o)
            $('#typeAReset').bind("click",function (){
             console.log('加载题目:'+(i+1)+'/'+dataLength)
                reset(dataLength,"A")
        },0,jsonData,i,dataLength)
            })
    }
            $('#typeBReset').bind("click",function (){
}
                reset(dataLength,"B")
function addAfter(id,content) {
            })
    var data = $('.data')
            $('#typeCReset').bind("click",function (){
    content.insertAfter(data[id])
                reset(dataLength,"C")
}
            })
function isObjExist(target){
            $('#typeXReset').bind("click",function (){
    if($(target).length>0){return true;}else {return false;}
                reset(dataLength,"X")
}
            })
function render(id,type,obj,parent){
            for(var i=0;i<dataLength;i++){
    parent =parent !==undefined ?parent : '#subjectContainer-'+type
                var singleData = $(data[i]).text()
    if(typeof(parent)!=='object'){
                console.log(singleData)
        parent = $(parent)
                var jsonData = $.parseJSON(singleData)
    }
                setTimeout(function(jsonData,i){
    if(isObjExist(parent)){obj.appendTo(parent)}else {addAfter(id,obj)}
                console.log(jsonData)
}
                console.log(jsonData.type)
function dicLen(dic){
            eval('type'+jsonData.type+'Module('+i+')')
    var count=0;
            eval('type'+jsonData.type+'('+JSON.stringify(jsonData)+','+i+')')
    for(var key in dic){
                },0,jsonData,i)
        console.log(key+'='+dic[key]);
            }
        count++;
    }
    return count
}
function newTimu(id,json,hideButton,addHr,parent=''){
    parent = parent !== undefined ? parent : ''
    addHr = addHr !== undefined ? addHr : true
    hideButton = hideButton !== undefined ? hideButton : false
    var type = json.type
    var o = new Object()
    o.temp = {
        main:$('<div id="'+id+'" class="type'+type+'"></div>'),
        subject:$('<div class="subject"></div>'),
        range:$('<div class="sourceRange"></div>'),
        info:$('<div class="info"></div>'),
        titleCon:$('<div class="titleContainer"></div>'),
        source:$('<p class="source"></p>'),
        title:$('<p class="title"></p>'),
        options:$('<div class="options"></div>'),
        btn:$('<button class="button-small button-pill button button-caution" id="showSingle-' + id + '" class="showSingleBtn">提交</button>'),
        ansCon:$('<div id="ansContainer" class="ansContainer noDisplay"></div>'),
        correct:$('<p style="display:inline;"><b>正确答案:</b></p><p class="correctAnswer"></p><br>'),
        explain:$('<p style="display:inline;"><b>解析: </b></p><p class="explain"></p><br>'),
        select:$('<select class="button-small button-rounded button"></select>'),
        subTitle:$('<div id=""></div>')
    }
    o.hideButton = hideButton
    o.parent = parent
    if(type!=='A3'&&type!=='PD'){
        o.temp.btn.bind("click",function (){
            showChoiceAnswer(id,type,json.answer)
        })
    }
 
    o.A = function () {
        this.temp.source.text(json.source)
        this.temp.title.text(json.title)
        this.temp.correct.nextAll('.correctAnswer').text(json.answer)
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)
        var options = formatAnsDic(json.choices)
        for(var k in options) {
            var label = '<label id="' + k + '"><input name="singelChoice-' + id + '" type="radio" value="' + k + '" />' + k + '' + options[k] + '</label>'
            this.temp.options.append(label)
         }
         }
         function removeBackground(obj){
         this.temp.titleCon.append(this.temp.source,this.temp.title)
            obj.addClass('no-background')
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
        }
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
                function showChoiceAnswer(id,type){
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
            var subjectCon = $('#'+id)
        this.temp.main.append(this.temp.subject,this.temp.ansCon)
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
            var ansCon = subjectCon.children('.ansContainer')
            var answers = subjectCon.children('.subject').children('.answers')
            var correctAns= ansCon.children('.correctAnswer')
            console.log(id)
            if(type==="A"){
                var correctAnsText = correctAns.text()
                var choice = $('input[name="singelChoice-'+id+'"]:checked').val();
                console.log(choice)
                var showCorrect = answers.children('#'+correctAnsText)
                var showChoice = answers.children('#'+choice)
                $('#showSingle-'+id).addClass('noDisplay')
                ansCon.fadeIn(100)
                if(choice===correctAnsText){
                    showCorrect.addClass('correct')
                }else{
                    showCorrect.addClass('correct')
                    showChoice.addClass('wrong')
                }
                setTimeout(function (){
                    removeBackground(showChoice)
                    removeBackground(showCorrect)
                }, 4000);


                setTimeout(function (){
        if(addHr){this.temp.main.append('<hr>')}
                    showCorrect.removeClass('no-background')
        return this.temp.main
                    showChoice.removeClass('no-background')
    }
                    showCorrect.removeClass('correct')
    o.A3 = function () {
                    showChoice.removeClass('wrong')
        var subIDs = []
                }, 5000);
        var s = json.source*1;var e = json.source*1+json.sourceRange*1 -1
            }else if(type==='A3'){
        this.temp.range.text(''+s+' '+e+' ')
                for(var i=0;i<id.length;i++){
        for(var i=0;i<json.title.length;i++){
                    var subID = id[i]
            subIDs.push(id+'-'+i)
                    var mainID = subID.split('-')[0]
            if(json.explain[i]==undefined){
                    subjectCon = $('#'+ id[i])
                 json.explain[i] = '暂无解析'
                    titleCon = subjectCon.children('.subject').children('.titleContainer')
            }
                    ansCon = subjectCon.children('.ansContainer')
            var data = {
                    answers = subjectCon.children('.subject').children('.answers')
                 "type":"A",
                    correctAns= ansCon.children('.correctAnswer')
                 "source":json.source+'-'+(i+1),
                    //以下与A型题时一样的代码,知识用subID替换ID变量
                 "title":json.title[i],
                    var correctAnsText = correctAns.text()
                 "answer":json.answer[i],
                    var choice = $('input[name="singelChoice-'+mainID+'-'+subID+'"]:checked').val();
                "explain":json.explain[i],
                    console.log(choice)
                "choices":json.choices[i],
                    var showCorrect = answers.children('#'+correctAnsText)
                    var showChoice = answers.children('#'+choice)
                    ansCon.fadeIn(100)
                    if(choice===correctAnsText){
                        showCorrect.addClass('correct')
                    }else{
                        showCorrect.addClass('correct')
                        showChoice.addClass('wrong')
                    }
                    setTimeout(function (){
                        removeBackground(showChoice)
                        removeBackground(showCorrect)
                    }, 4000);
 
                    setTimeout(function (){
                        showCorrect.removeClass('no-background')
                        showChoice.removeClass('no-background')
                        showCorrect.removeClass('correct')
                        showChoice.removeClass('wrong')
                    }, 5000);
                }
 
            } else if(type==='B'){
                console.log(titleCon)
                titleCon.children('div').each(function (index,i){
                    console.log(i)
                    var subTitleID = $(i).attr('id')
                    var ans = $('#ans-'+subTitleID).text().split(':')[1]
                    var choice = $('#'+id+'-'+index).find("option:selected").text();
                    console.log(choice)
                    if(choice==ans){
                        $('#'+id+'-'+index).addClass('correct')
                    }else {
                        $('#'+id+'-'+index).addClass('wrong')
                        $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))
 
                    }
                    setTimeout(function (){
                        $('#'+id+'-'+index).removeClass('correct')
                        $('#'+id+'-'+index).removeClass('wrong')
                    }, 5000);
                })
            } else if(type=="C"){
                console.log(titleCon)
                titleCon.children('div').each(function (index,i){
                    console.log(i)
                    var subTitleID = $(i).attr('id')
                    var ans = $('#ans-'+subTitleID).text().split(':')[1]
                    var choice = $('#'+id+'-'+index).find("option:selected").text();
                    console.log(choice)
                    if(choice==ans){
                        $('#'+id+'-'+index).addClass('correct')
                    }else {
                        $('#'+id+'-'+index).addClass('wrong')
                        $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))
 
                    }
                    setTimeout(function (){
                        $('#'+id+'-'+index).removeClass('correct')
                        $('#'+id+'-'+index).removeClass('wrong')
                    }, 5000);
                })
            }else if(type=="X"){
                var correctAnsText = correctAns.text()
                var choice = ""
                $('input[name="singelChoice-'+id+'"]:checked').each(function (){
                    choice += $(this).val()
                })
                console.log(choice)
                console.log(correctAnsText)
                var btn = $('#showSingle-'+id).addClass('noDisplay')
                ansCon.fadeIn(100)
                for(var i=0;i<choice.length;i++){
                    var showCorrect = answers.children('#'+correctAnsText[i])
                    var showChoice = answers.children('#'+choice[i])
                    if(correctAnsText.indexOf(choice[i])!=-1){
                        showChoice.addClass('correct')
                    }else{
                        showChoice.addClass('wrong')
                    }
                 }
                for(var i=0;i<correctAnsText.length;i++){
                    var showCorrect = answers.children('#'+correctAnsText[i])
                    $('<p class="answerTip">✓</p>').appendTo(showCorrect)
                }
                answers.children('label').each(function (){
                    var a = $(this)
                    setTimeout(function (){
                        removeBackground(a)
                    }, 4000);
                    setTimeout(function (){
                        a.removeClass('no-background')
                        a.removeClass('correct')
                        a.removeClass('wrong')
                    }, 5000);
                 })
            }else if(type=="TK"){
                $('#showSingle-'+id).addClass('noDisplay')
                ansCon.fadeIn(100)
                var correctAnsText = correctAns.text()
                var answers = correctAns.text().split(',')
                 console.log(answers[0])
                var form =$('#form-'+id).serializeArray()
                 var myAns = []
                console.log(form[0]['value'])
                 for(var i=0;i<form.length;i++){
                    var input = $('#form-'+id).children('#'+id+'-'+i)
                    if(answers[i] != form[i]['value']){
                        $('<p class="wrong TKcheck">'+answers[i]+'</p>').insertAfter(input)
                    }else{
                        $('<p class="correct TKcheck">'+answers[i]+'</p>').insertAfter(input)
                    }
                }
             }
             }
            var newA = newTimu(id+'-'+i,data,true,false).A()
            render(id+'-'+i,'A',newA,this.temp.titleCon)
         }
         }
         function reset(length,type){
         o.temp.btn.bind("click",function (){
            if(type=="A"){
            showChoiceAnswer(subIDs,type,json.answer)
                for(var id=0;id<length;id++){
        })
                    var choice = $('input:radio').removeAttr('checked')
        this.temp.info.text(json.info)
                    var subjectCon = $('#subjectContainer-'+type).children('#'+id)
        this.temp.subject.append(this.temp.range,this.temp.info,this.temp.titleCon)
                    var ansCon = subjectCon.children('.ansContainer')
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
                    $('#showSingle-'+id).removeClass('noDisplay')
        this.temp.main.append(this.temp.subject)
                    ansCon.fadeOut(100)
 
                }
        if(addHr){this.temp.main.append('<hr>')}
            }else if(type=="B"){
        return this.temp.main
                $('.answerTip').css('display','none')
    }
                var typeBselected=$('#subjectContainer-B').children('.typeB').children('.subject').children('.titleContainer').children('div').children('select')
    o.B = function () {
                typeBselected.each(function () {
        var s = json.source*1;var e = json.source*1+json.sourceRange*1 -1
                    $(this).children("option").eq(0).prop("selected",true)
        this.temp.range.text(''+s+' '+e+' ')
                })
            }else if(type=="C"){
                $('.answerTip').css('display','none')
                var typeBselected=$('#subjectContainer-C').children('.typeC').children('.subject').children('.titleContainer').children('div').children('select')
                typeBselected.each(function () {
                    $(this).children("option").eq(0).prop("selected",true)
                })
            }else if(type=="X") {
                $('.answerTip').css('display', 'none')
                for (var id = 0; id < length; id++) {
                    var choice = $('input:checkbox').each(function () {
                        $(this).prop('checked', false)
                    })
                    var subjectCon = $('#subjectContainer-' + type).children('#' + id)
                    var ansCon = subjectCon.children('.ansContainer')
                    $('#showSingle-' + id).removeClass('noDisplay')
                    ansCon.fadeOut(100)
                }
            }else if(type=="TK") {
                $('.TKcheck').each(function (a) {
                    $(this).remove()
                })
                for(var id=0;id<length;id++){
                    var choice = $('input:radio').removeAttr('checked')
                    var subjectCon = $('#subjectContainer-'+type).children('#'+id)
                    var ansCon = subjectCon.children('.ansContainer')
                    $('#showSingle-'+id).removeClass('noDisplay')
                    ansCon.fadeOut(100)
                }
            }


        var options = formatAnsDic(json.choices)
        for(var k in options){
            var label = '<li id="'+k+'">'+k+':'+options[k]+'</li>'
            this.temp.options.append(label)
            this.temp.select.append('<option value="'+k+'">'+k+'</option>')
         }
         }
         function addAfter(id,content) {
         for(var i=0;i<json.title.length;i++){
             var data = $('.data')
             var reg1 = /\(\)/g
             console.log(content)
             var text = json.title[i]
            console.log(data[id])
             if(reg1.test(text)){
             content.insertAfter(data[id])
                text = text.replace("()",this.temp.select.prop("outerHTML"))
        }
             }else{
        function isObjExist(target){
                 text += this.temp.select.prop("outerHTML")
            if($(target).length>0){
                return true
             }else {
                 return false
             }
             }
            this.temp.subTitle.attr('id',id+'-'+i)
            this.temp.source.text(s+i)
            this.temp.subTitle.html(this.temp.source.prop("outerHTML")+text)
            this.temp.titleCon.append(this.temp.subTitle.prop("outerHTML"))
         }
         }
              //A1型题
         for(var i=0;i<json.answer.length;i++){
         function typeA(json,id,parent){
            this.temp.correct.nextAll('.correctAnswer').append('<p id="ans-'+id +'-'+i+'">'+(id+i)+':'+json.answer[i]+'</p>')
            parent =parent !==undefined ?parent : '#subjectContainer-A'
            var subjectCon
            if(isObjExist(parent)){
                subjectCon = $(parent).children('#'+id)
            }else {
                subjectCon = $('#'+id)
            }
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
            var ansCon = subjectCon.children('.ansContainer')
            var source = titleCon.children('.source').text(json.source)
            var title = titleCon.children('.title').text(json.title)
            var correctAns = ansCon.children('.correctAnswer').text(json.answer)
            var exp = ansCon.children('.explain').text(json.explain)
            var answers = subjectCon.children('.subject').children('.answers')
            var charStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
            var ansList = []
            for(var n=0;n<charStr.length;n++){
                if(json.choices[charStr[n]]==undefined || json.choices[charStr[n]]==null){
                    continue
                }
                if(json.choices[charStr[n]].length>0){
                    ansList.push(json.choices[charStr[n]])
                }
            }
            for(var i = 0;i<ansList.length;i++){
                var label = '<label id="'+charStr[i]+'"><input name="singelChoice-'+id+'" type="radio" value="'+charStr[i]+'" />'+charStr[i]+':'+ansList[i]+'</label>'
                answers.append(label)
            }
         }
         }
         function typeAModule(id,parent,isA3){
         for(var i=0;i<json.explain.length;i++){
            parent =parent !==undefined ?parent : '#subjectContainer-A'
             this.temp.explain.nextAll('.explain').append('<p id="exp-'+id +'-'+i+'">'+(id+i)+''+json.explain[i]+'</p>')
            isA3 = isA3 !== undefined ? isA3 : false
            var main = $('<div id="'+id+'" class="typeA"></div>')
             var subject = $('<div class="subject">' +
                '<div class="titleContainer"><p class="source"></p><p class="title"></p></div>' +
                '<div class="answers"></div></div>').appendTo(main)
            if(!isA3) {
                var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-' + id + '" class="showSingleBtn">提交</button>').appendTo(main)
            }
            var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
            '           <p style="display:inline;"><b>正确答案:</b></p>\n' +
            '            <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
            '           <p class="explain"></p></div><hr>').appendTo(main)
            if(isObjExist(parent)){
                main.appendTo($(parent))
            }else {
                addAfter(id,main)
            }
            if(!isA3){
                $("#showSingle-"+id).bind("click",function (){
                    showChoiceAnswer(id,'A')
                })
            }
         }
         }
        function typeA2Module(id,parent){
            var main = $('<div id="'+id+'" class="typeA2"></div>')
            var subject = $('<div class="subject">' +
                '<div class="titleContainer"><p class="source"></p><p class="title"></p></div>' +
                '<div class="answers"></div></div>').appendTo(main)
            var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
            var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
                '            <p style="display:inline;"><b>正确答案:</b></p>\n' +
                '            <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
                '            <p class="explain"></p></div><hr>').appendTo(main)


            parent =parent !==undefined ?parent : '#subjectContainer-A2'
        this.temp.subject.append(this.temp.range,this.temp.options,this.temp.titleCon)
            if(isObjExist(parent)){
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
                main.appendTo($(parent))
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
            }else {
        this.temp.main.append(this.temp.subject,this.temp.ansCon)
                addAfter(id,main)
 
            }
        if(addHr){this.temp.main.append('<hr>')}
            $("#showSingle-"+id).bind("click",function (){
        return this.temp.main
                showChoiceAnswer(id,'A')
    }
             })
    o.C = function () {
        var s = json.source*1;var e = json.source*1+json.sourceRange*1 -1
        this.temp.range.text('第 '+s+' 到 '+e+' 题')
 
        var options = formatAnsDic(json.choices)
        for(var k in options){
            var label = '<li id="'+k+'">'+k+':'+options[k]+'</li>'
            this.temp.options.append(label)
             this.temp.select.append('<option value="'+k+'">'+k+'</option>')
         }
         }
         function typeA2(json,id){
         for(var i=0;i<json.title.length;i++){
            var parent = '#subjectContainer-A2'
             var reg1 = /\(\)/g
            var subjectCon
             var text = json.title[i]
            if(isObjExist(parent)){
             if(reg1.test(text)){
                subjectCon = $(parent).children('#'+id)
                text = text.replace("()",this.temp.select.prop("outerHTML"))
            }else {
             }else{
                subjectCon = $('#'+id)
                 text += this.temp.select.prop("outerHTML")
            }
            var subjectCon
            if(isObjExist(parent)){
                subjectCon = $(parent).children('#'+id)
            }else {
                subjectCon = $('#'+id)
            }
             var titleCon = subjectCon.children('.subject').children('.titleContainer')
            var ansCon = subjectCon.children('.ansContainer')
             var source = titleCon.children('.source').text(json.source)
            var title = titleCon.children('.title').text(json.title)
             var correctAns = ansCon.children('.correctAnswer').text(json.answer)
            var exp = ansCon.children('.explain').text(json.explain)
            var answers = subjectCon.children('.subject').children('.answers')
             var charStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
            var ansList = []
            for(var n=0;n<charStr.length;n++){
                 if(json.choices[charStr[n]]==undefined || json.choices[charStr[n]]==null){
                    continue
                }
                if(json.choices[charStr[n]].length>0){
                    ansList.push(json.choices[charStr[n]])
                }
            }
            for(var i = 0;i<ansList.length;i++){
                var label = '<label id="'+charStr[i]+'"><input name="singelChoice-'+id+'" type="radio" value="'+charStr[i]+'" />'+charStr[i]+':'+ansList[i]+'</label>'
                answers.append(label)
             }
             }
            this.temp.subTitle.attr('id',id+'-'+i)
            this.temp.source.text(s+i)
            this.temp.subTitle.html(this.temp.source.prop("outerHTML")+text)
            this.temp.titleCon.append(this.temp.subTitle.prop("outerHTML"))
         }
         }
         function typeA3(json,id){
         for(var i=0;i<json.answer.length;i++){
            const char = ['A','B','C','D','E',]
             this.temp.correct.nextAll('.correctAnswer').append('<p id="ans-'+id +'-'+i+'">'+(id+i)+':'+json.answer[i]+'</p>')
            var subIDs = []
            var parent = '#subjectContainer-A3'
            var subjectCon
            if(isObjExist(parent)){
                subjectCon = $(parent).children('#'+id)
            }else {
                subjectCon = $('#'+id)
            }
            var subject = subjectCon.children('.subject')
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
            var ansCon = subjectCon.children('.ansContainer')
            var source = json.source
            var range = json.sourceRange
            var choices = json.choices
            var answer = json.answer
            var end = source *1 + range*1 -1
            var title = json.title
            var exp = json.explain
            ansCon.children('.explain').text(json.explain)
             subject.children('.info').text(json.info)
            subjectCon.children('.subject').children('.answers')
            subject.children('.sourceRange').text('第 '+source+' 到 '+end+' 题')
            for(var i=0;i<title.length;i++){
                subIDs.push(id+'-'+i)
                typeAModule(id+'-'+i,titleCon,true)
                var explain
                if(exp[i]==undefined){
                    explain = '暂无解析'
                }else {
                    explain = exp[i]
                }
                var data = {
                    "type":"A",
                    "source":source+'-'+(i+1),
                    "title":title[i],
                    "answer":answer[i],
                    "explain":explain,
                    "choices":{},
                }
                for(var j=0;j<dicLen(choices[i]);j++){
                    data.choices[char[j]]=choices[i][char[j]]
                }
                console.log(data)
                typeA(data,id+'-'+i,titleCon)
            }
            $("#showSingle-"+id).bind("click",function (){
                showChoiceAnswer(subIDs,'A3')
            })
         }
         }
         function typeA3Module(id){
         for(var i=0;i<json.explain.length;i++){
            var main = $('<div id="'+id+'" class="typeA3"></div>')
             this.temp.explain.nextAll('.explain').append('<p id="exp-'+id +'-'+i+'">'+(id+i)+''+json.explain[i]+'</p>')
             var subject = $('<div class="subject">' +
                '<div class="sourceRange"></div>'+
                '<div class="info"></div>'+
                '<div class="titleContainer"></div></div>'
            ).appendTo(main)
            $('<button class="button-small button-pill button button-caution" id="showSingle-' + id + '" class="showSingleBtn">提交</button>').appendTo(main)
            var parent = '#subjectContainer-A3'
            if(isObjExist(parent)){
                main.appendTo($(parent))
            }else {
                addAfter(id,main)
            }
         }
         }
        //B型题
 
         function typeB(json,id){
         this.temp.subject.append(this.temp.range,this.temp.titleCon,this.temp.options)
            var parent = '#subjectContainer-B'
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
            var subjectCon
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
            if(isObjExist(parent)){
        this.temp.main.append(this.temp.subject,this.temp.ansCon)
                subjectCon = $(parent).children('#'+id)
 
            }else {
        if(addHr){this.temp.main.append('<hr>')}
                subjectCon = $('#'+id)
        return this.temp.main
            }
    }
            var subject = subjectCon.children('.subject')
    o.X = function () {
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
        this.temp.source.text(json.source)
            var ansCon = subjectCon.children('.ansContainer')
        this.temp.title.text(json.title)
            var source = json.source
        this.temp.correct.nextAll('.correctAnswer').text(json.answer)
            var range = json.sourceRange
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)
            var end = source *1 + range*1 -1
        var options = formatAnsDic(json.choices)
            var title = json.title
        for(var k in options){
            var correctAns = json.answer
            var label = '<label id="'+k+'"><input name="singelChoice-'+id+'" type="checkbox" value="'+k+'" />'+k+':'+options[k]+'</label>'
            var exp = ansCon.children('.explain').text(json.explain)
            this.temp.options.append(label)
            var answers = subjectCon.children('.subject').children('.answers')
            var char = ['A: ','B: ','C: ','D: ','E: ','F: ','G: ','H: ','I: ','J: ',]
            var sourceRange = subject.children('.sourceRange').text('第 '+source+' 到 '+end+' 题')
            for(var m=0;m<title.length;m++){
                var text = title[m]
                var reg1 = /\(\)/g
                var reg2 = new RegExp('\( +\)','g')
                var select = "(<select class=\"button-small button-rounded button\"> "
                for(var j=0;j<dicLen(json.choices);j++){
                    var opt = char[j].split(': ')[0]
                    if(json.choices[opt].length>0){
                        select+="<option value ='"+opt+"'>"+opt+"</option>"
                    }
                }
                select+="</select>)"
                console.log(select)
                if(reg1.test(text)){
                    text = title[m].replace("()",select)
                }else{
                    text += select
                }
                var div = '<div id="'+id+'-'+m+'"><p class="source">'+'T'+(source*1+m)+'</p>'+text+'</div>'
                titleCon.append(div)
            }
            var i = 0
            for(var key in json.choices){
                if(json.choices[key].length>0){
                    var label = '<li id="'+key+'">'+char[i]+json.choices[key]+'</li>'
                    answers.append(label)
                    console.log(label)
                }
                i+=1
            }
            text = ''
            for(var n=0;n<correctAns.length;n++){
                text += '<p id="ans-'+id +'-'+n+'">'+(id*1+n)+':'+correctAns[n]+'</p>'
                ansCon.children('.correctAnswer').html(text)
            }
         }
         }
         function typeBModule(id){
 
            var main = $('<div id="'+id+'" class="typeB"></div>')
        this.temp.titleCon.append(this.temp.source,this.temp.title)
            var subject = $('<div class="subject">' +
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
                '<div class="sourceRange"></div>'+
         this.temp.subject.append(this.temp.titleCon,this.temp.options)
                '<div class="answers"></div>'+
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
                '<div class="titleContainer"></div></div>'
        this.temp.main.append(this.temp.subject,this.temp.ansCon)
                ).appendTo(main)
 
            var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
        if(addHr){this.temp.main.append('<hr>')}
            var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
        return this.temp.main
                '           <p style="display:inline;"><b>正确答案:</b></p>\n' +
    }
                '           <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
    o.PD = function () {
                '           <p class="explain"></p></div><hr>').appendTo(main)
        this.temp.source.text(json.source)
             var parent = '#subjectContainer-B'
        this.temp.title.text(json.title)
            if(isObjExist(parent)){
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)
                main.appendTo($(parent))
        var ans = ''
            }else {
        if(json.answer=='T' || json.answer=='正确' || json.answer=='1' || json.answer=='√'){
                addAfter(id,main)
             ans = '正确'
             }
        }else if(json.answer=='F' || json.answer=='错误' || json.answer=='0' || json.answer=='×'){
            $("#showSingle-"+id).bind("click",function (){
             ans = '错误'
                showChoiceAnswer(id,'B')
            })
         }
         }
         //C型题
         this.temp.correct.nextAll('.correctAnswer').text(ans)
         function typeCModule(id){
         o.temp.btn.bind("click",function (){
             var main = $('<div id="'+id+'" class="typeC"></div>')
             showChoiceAnswer(id,'A',ans)
             var subject = $('<div class="subject">' +
        })
                '<div class="sourceRange"></div>'+
        this.temp.options.append('<label id="正确" style="display: inline;"><input name="singelChoice-'+id+'" type="radio" value="正确" />正确</label>' +
                '<div class="titleContainer"></div>'+
             '<label id="错误" style="display: inline;"><input name="singelChoice-'+id+'" type="radio" value="错误" />错误</label>')
                '<div class="answers"></div></div>'
        this.temp.titleCon.append(this.temp.source,this.temp.title)
            ).appendTo(main)
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
            var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
            var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
                '           <p style="display:inline;"><b>正确答案:</b></p>\n' +
        this.temp.main.append(this.temp.subject,this.temp.ansCon)
                '            <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
 
                '            <p class="explain"></p></div><hr>').appendTo(main)
        if(addHr){this.temp.main.append('<hr>')}
            var parent = '#subjectContainer-C'
        return this.temp.main
            if(isObjExist(parent)){
    }
                main.appendTo($(parent))
    o.TK = function () {
            }else {
        this.temp.source.text(json.source)
                addAfter(id,main)
        var form = $('<form id="form-'+id+'" class="title"></form>')
             }
        var pos = json.pos
            $("#showSingle-"+id).bind("click",function (){
        var posReg = new RegExp(pos,'g')
                showChoiceAnswer(id,'C')
        var posCount = json.title.match(posReg).length
            })
        for(var i=0;i<posCount;i++){
             json.title = json.title.replace(pos,'<input name="'+id+'-'+i+'" id="'+id+'-'+i+'" type="text" form="form-'+id+'"/>')
         }
         }
         function typeC(json,id){
         form.html(json.title)
            var parent = '#subjectContainer-C'
        this.temp.title.text(json.title)
            var subjectCon
        this.temp.correct.nextAll('.correctAnswer').text(json.answer)
            if(isObjExist(parent)){
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)
                subjectCon = $(parent).children('#'+id)
 
            }else {
        this.temp.titleCon.append(this.temp.source,form)
                subjectCon = $('#'+id)
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
            }
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
            var subject = subjectCon.children('.subject')
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
        this.temp.main.append(this.temp.subject,this.temp.ansCon)
            var ansCon = subjectCon.children('.ansContainer')
 
            var source = json.source
        if(addHr){this.temp.main.append('<hr>')}
            var range = json.sourceRange
        return this.temp.main
            var end = source *1 + range*1 -1
    }
            var title = json.title
    o.MJ = function () {
            var correctAns = json.answer
        this.temp.source.text(json.source)
            var exp = ansCon.children('.explain').text(json.explain)
        this.temp.title.html(json.title + ':<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>')
            var answers = subjectCon.children('.subject').children('.answers')
        this.temp.titleCon.append(this.temp.source,this.temp.title)
            var char = ['A: ','B: ','C: ','D: ','E: ','F: ','G: ','H: ','I: ','J: ',]
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
            var sourceRange = subject.children('.sourceRange').text('第 '+source+' 到 '+end+' 题')
        this.temp.main.append(this.temp.subject)
            for(var m=0;m<title.length;m++){
                var text = title[m]
                var reg1 = /\(\)/g
                var reg2 = new RegExp('\( +\)','g')
                var select = "(<select class=\"button-small button-rounded button\"> "
                for(var j=0;j<dicLen(json.choices);j++){
                    var opt = char[j].split(': ')[0]
                    if(json.choices[opt].length>0){
                        select+="<option value ='"+opt+"'>"+opt+"</option>"
                    }
                }
                select+="</select>)"
                console.log(select)
                if(reg1.test(text)){
                    text = title[m].replace("()",select)
                }else{
                    text += select
                }
                var div = '<div id="'+id+'-'+m+'"><p class="source">'+'T'+(source*1+m)+'</p>'+text+'</div>'
                titleCon.append(div)
            }
            var i = 0
            for(var key in json.choices){
                if(json.choices[key].length>0){
                    var label = '<li id="'+key+'">'+char[i]+json.choices[key]+'</li>'


                    answers.append(label)
        if(addHr){this.temp.main.append('<hr>')}
                    console.log(label)
        return this.temp.main
                }
    }
                i+=1
    return o
            }
}
            text = ''
function formatAnsDic(d) {
            for(var n=0;n<correctAns.length;n++){
    var c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                text += '<p id="ans-'+id +'-'+n+'">'+(id*1+n)+':'+correctAns[n]+'</p>'
    var dic = {}
                ansCon.children('.correctAnswer').html(text)
    for(var i=0;i<c.length;i++){
             }
        if(d?.[c[i]]||''.length>0){
             dic[c[i]] = d[c[i]]
         }
         }
        //X型题
    }
        function typeX(json,id){
    return dic
            var parent = '#subjectContainer-X'
}
            var subjectCon
function showAns(id,type,correctAnswer){
            if(isObjExist(parent)){
    var s = new Object()
                subjectCon = $(parent).children('#'+id)
}
            }else {
function showChoiceAnswer(id,type,correctAnswer){
                subjectCon = $('#'+id)
    var subjectCon = $('#'+id)
            }
    var titleCon = subjectCon.children('.subject').children('.titleContainer')
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
    var ansCon = subjectCon.children('.ansContainer')
            var ansCon = subjectCon.children('.ansContainer')
    var answers = subjectCon.children('.subject').children('.options')
            var source = titleCon.children('.source').text(json.source)
    console.log(correctAnswer)
            var title = titleCon.children('.title').text(json.title)
    if(type==="A"){
            var correctAns = ansCon.children('.correctAnswer').text(json.answer)
        var correctAnsText = correctAnswer
            var exp = ansCon.children('.explain').text(json.explain)
        var choice = $('input[name="singelChoice-'+id+'"]:checked').val();
            var answers = subjectCon.children('.subject').children('.answers')
        console.log(choice)
            var char = ['A: ','B: ','C: ','D: ','E: ',]
        var showCorrect = answers.children('#'+correctAnsText)
            var i = 0
        var showChoice = answers.children('#'+choice)
            for(var key in json.choices){
        $('#showSingle-'+id).addClass('noDisplay')
                if(json.choices[key].length>0){
        ansCon.fadeIn(100)
                    var label = '<label id="'+key+'"><input name="singelChoice-'+id+'" type="checkbox" value="'+key+'" />'+char[i]+json.choices[key]+'</label>'
        if(choice===correctAnsText){
                    answers.append(label)
            showCorrect.addClass('correct')
                }
        }else{
                i+=1
            showCorrect.addClass('correct')
            }
            showChoice.addClass('wrong')
         }
         }
         function typeXModule(id){
         setTimeout(function (){
             var main = $('<div id="'+id+'" class="typeX"></div>')
            removeBackground(showChoice)
             var subject = $('<div class="subject">' +
            removeBackground(showCorrect)
                '<div class="titleContainer"><p class="source"></p><p class="title"></p></div>' +
        }, 4000);
                '<div class="answers"></div></div>').appendTo(main)
 
            var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
        setTimeout(function (){
            var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
             showCorrect.removeClass('no-background')
                '            <p style="display:inline;"><b>正确答案:</b></p>\n' +
            showChoice.removeClass('no-background')
                '           <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
             showCorrect.removeClass('correct')
                '            <p class="explain"></p></div><hr>').appendTo(main)
            showChoice.removeClass('wrong')
             var parent = '#subjectContainer-X'
        }, 5000);
             if(isObjExist(parent)){
    }else if(type==='A3'){
                main.appendTo($(parent))
        $('#showSingle-'+id).addClass('noDisplay')
             }else {
        for(var i=0;i<id.length;i++){
                addAfter(id,main)
            var subID = id[i]
            }
            var mainID = subID.split('-')[0]
             $("#showSingle-"+id).bind("click",function (){
            console.log(subID)
                showChoiceAnswer(id,'X')
            console.log(mainID)
            })
             subjectCon = $('#'+ id[i])
             titleCon = subjectCon.children('.subject').children('.titleContainer')
            ansCon = subjectCon.children('.ansContainer')
             answers = subjectCon.children('.subject').children('.options')
             $('#showSingle-'+id).addClass('noDisplay')
            var correctAns= correctAnswer[i]
            //以下与A型题时一样的代码,知识用subID替换ID变量
            showChoiceAnswer(subID,'A',correctAns)
         }
         }
         //判断题
 
         function typePD(json,id){
    } else if(type==='B'){
             var parent = '#subjectContainer-PD'
         console.log(titleCon)
             var subjectCon
         titleCon.children('div').each(function (index,i){
             if(isObjExist(parent)){
            console.log(i)
                subjectCon = $(parent).children('#'+id)
             var subTitleID = $(i).attr('id')
             var ans = correctAnswer[index]
             var choice = $('#'+id+'-'+index).find("option:selected").text();
            $('#showSingle-'+id).addClass('noDisplay')
            console.log(choice)
            if(choice==ans){
                $('#'+id+'-'+index).addClass('correct')
             }else {
             }else {
                 subjectCon = $('#'+id)
                 $('#'+id+'-'+index).addClass('wrong')
            }
                $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
 
            var ansCon = subjectCon.children('.ansContainer')
            titleCon.children('.source').text(json.source)
            titleCon.children('.title').text(json.title)
            ansCon.children('.explain').text(json.explain)
            if(json.answer=='T' || json.answer=='正确' || json.answer=='1' || json.answer=='√'){
                ansCon.children('.correctAnswer').text('正确')
            }else if(json.answer=='F' || json.answer=='错误' || json.answer=='0' || json.answer=='×'){
                ansCon.children('.correctAnswer').text('错误')
             }
             }
        }
            setTimeout(function (){
        function typePDModule(id){
                $('#'+id+'-'+index).removeClass('correct')
            var main = $('<div id="'+id+'" class="typePD"></div>')
                 $('#'+id+'-'+index).removeClass('wrong')
            var subject = $('<div class="subject">' +
            }, 5000);
                 '<div class="titleContainer"><p class="source"></p><p class="title"></p></div>' +
        })
                '<div class="answers">' +
    } else if(type=="C"){
                '<label id="正确" style="display: inline;"><input name="singelChoice-'+id+'" type="radio" value="正确" />正确</label>' +
        console.log(titleCon)
                '<label id="错误" style="display: inline;"><input name="singelChoice-'+id+'" type="radio" value="错误" />错误</label>' +
        $('#showSingle-'+id).addClass('noDisplay')
                '</div></div>').appendTo(main)
        titleCon.children('div').each(function (index,i){
             var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
            console.log(i)
             var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
             var subTitleID = $(i).attr('id')
                '           <p style="display:inline;"><b>正确答案:</b></p>\n' +
            var ans = correctAnswer[index]
                '            <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
             var choice = $('#'+id+'-'+index).find("option:selected").text();
                '            <p class="explain"></p></div><hr>').appendTo(main)
             console.log(choice)
             var parent = '#subjectContainer-PD'
             if(choice==ans){
             if(isObjExist(parent)){
                 $('#'+id+'-'+index).addClass('correct')
                 main.appendTo($(parent))
             }else {
             }else {
                 addAfter(id,main)
                 $('#'+id+'-'+index).addClass('wrong')
            }
                 $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))
            $("#showSingle-"+id).bind("click",function (){
 
                showChoiceAnswer(id,'A')
            })
        }
        function typeTK(json,id){
            var parent = '#subjectContainer-TK'
            var subjectCon
            if(isObjExist(parent)){
                subjectCon = $(parent).children('#'+id)
            }else {
                subjectCon = $('#'+id)
            }
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
            var ansCon = subjectCon.children('.ansContainer')
            var source = titleCon.children('.source').text(json.source)
            console.log(source)
            var correctAns = ansCon.children('.correctAnswer').text(json.answer)
            var exp = ansCon.children('.explain').text(json.explain)
            var pos = json.pos
            var title = json.title
            var reg = new RegExp(pos,'g')
            var subID = 0
            var posCount = title.match(reg).length
            for(var i=0;i<posCount;i++){
                 title = title.replace(pos,'<input name="'+id+'-'+i+'" id="'+id+'-'+i+'" type="text" form="form-'+id+'"/>')
                console.log(title)
             }
             }
             titleCon.children('.title').html(title)
             setTimeout(function (){
        }
                $('#'+id+'-'+index).removeClass('correct')
        function typeTKModule(id){
                $('#'+id+'-'+index).removeClass('wrong')
            var main = $('<div id="'+id+'" class="typeTK"></div>')
             }, 5000);
             var subject = $('<div class="subject"><div class="titleContainer"><p class="source"></p><form id="form-'+id+'" class="title"></form></div></div>').appendTo(main)
        })
             var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
    }else if(type=="X"){
            var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
        var correctAnsText = correctAnswer
                '            <p style="display:inline;"><b>正确答案:</b></p>\n' +
        var choice = ""
                '            <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
        $('input[name="singelChoice-'+id+'"]:checked').each(function (){
                '            <p class="explain"></p></div><hr>').appendTo(main)
             choice += $(this).val()
             var parent = '#subjectContainer-TK'
        })
             if(isObjExist(parent)){
        console.log(choice)
                 main.appendTo($(parent))
        console.log(correctAnsText)
             }else {
        var btn = $('#showSingle-'+id).addClass('noDisplay')
                 addAfter(id,main)
        ansCon.fadeIn(100)
        for(var i=0;i<choice.length;i++){
            var showCorrect = answers.children('#'+correctAnsText[i])
             var showChoice = answers.children('#'+choice[i])
             if(correctAnsText.indexOf(choice[i])!=-1){
                 showChoice.addClass('correct')
             }else{
                 showChoice.addClass('wrong')
             }
             }
            $("#showSingle-"+id).bind("click",function (){
                showChoiceAnswer(id,'TK')
            })
         }
         }
         //名词解释
         for(var i=0;i<correctAnsText.length;i++){
        function typeMJ(json,id){
             console.log(i)
            var parent = '#subjectContainer-MJ'
             var showCorrect = answers.children('#'+correctAnsText[i])
            var subjectCon
             $('<p class="answerTip"></p>').appendTo(showCorrect)
            if(isObjExist(parent)){
                subjectCon = $(parent).children('#'+id)
            }else {
                subjectCon = $('#'+id)
            }
            var titleCon = subjectCon.children('.subject').children('.titleContainer')
            var ansCon = subjectCon.children('.ansContainer')
            var source = titleCon.children('.source').text(json.source)
             console.log(source)
             var correctAns = ansCon.children('.correctAnswer').text(json.answer)
            var exp = ansCon.children('.explain').text(json.explain)
            var pos = json.pos
            var title = json.title
            var reg = new RegExp(pos,'g')
            var subID = 0
            var posCount = title.match(reg).length
            if(json.inputBox*1){
                title += '<input name="'+id+'" id="'+id+'" type="text"/>'
             }else {
                ansCon.remove()
                $("#showSingle-"+id).remove()
                title = title +'<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>'
            }
            titleCon.children('.title').html(title)
         }
         }
         function typeMJModule(id){
         answers.children('label').each(function (){
             var main = $('<div id="'+id+'" class="typeMJ"></div>')
             var a = $(this)
             var subject = $('<div class="subject"><div class="titleContainer"><p class="source"></p></div></div>').appendTo(main)
            setTimeout(function (){
            var showButton = $('<button class="button-small button-pill button button-caution" id="showSingle-'+id+'" class="showSingleBtn">提交</button>').appendTo(main)
                removeBackground(a)
             var ansCon = $('<div id="ansContainer" class="ansContainer noDisplay">' +
            }, 4000);
                '           <p style="display:inline;"><b>正确答案:</b></p>\n' +
            setTimeout(function (){
                 '           <p class="correctAnswer"></p><br><p style="display:inline;"><b>解析: </b></p>\n' +
                a.removeClass('no-background')
                 '           <p class="explain"></p></div><hr>').appendTo(main)
                a.removeClass('correct')
            var parent = '#subjectContainer-MJ'
                a.removeClass('wrong')
            if(isObjExist(parent)){
             }, 5000);
                main.appendTo($(parent))
        })
            }else {
    }else if(type=="TK"){
                addAfter(id,main)
        $('#showSingle-'+id).addClass('noDisplay')
        ansCon.fadeIn(100)
        var answers = correctAnswer
        console.log(answers[0])
        var form =$('#form-'+id).serializeArray()
        var myAns = []
        console.log(form[0]['value'])
        for(var i=0;i<form.length;i++){
             var input = $('#form-'+id).children('#'+id+'-'+i)
            if(answers[i] != form[i]['value']){
                 $('<p class="wrong TKcheck">'+answers[i]+'</p>').insertAfter(input)
            }else{
                 $('<p class="correct TKcheck">'+answers[i]+'</p>').insertAfter(input)
             }
             }
            $("#showSingle-"+id).bind("click",function (){
                showChoiceAnswer(id,'TK')
            })
         }
         }
function dicLen(dic){
    var count=0;
    for(var key in dic){
        console.log(key+'='+dic[key]);
        count++;
     }
     }
    return count
}
}
setTimeout(function (){
function removeBackground(obj){
getdata();
    obj.addClass('no-background')
},0);
}

2022年10月13日 (四) 02:05的版本

function getdata(){
    var data = $('.data')
    var dataLength = data.length
    for(var i=0;i<dataLength;i++){
        var singleData = $(data[i]).text()
        var jsonData = $.parseJSON(singleData)
        setTimeout(function(jsonData,i,dataLength){
            var o = eval('newTimu('+i+','+JSON.stringify(jsonData)+').'+jsonData.type+'()')
            render(i,jsonData.type,o)
            console.log('加载题目:'+(i+1)+'/'+dataLength)
        },0,jsonData,i,dataLength)
    }
}
function addAfter(id,content) {
    var data = $('.data')
    content.insertAfter(data[id])
}
function isObjExist(target){
    if($(target).length>0){return true;}else {return false;}
}
function render(id,type,obj,parent){
    parent =parent !==undefined ?parent : '#subjectContainer-'+type
    if(typeof(parent)!=='object'){
        parent = $(parent)
    }
    if(isObjExist(parent)){obj.appendTo(parent)}else {addAfter(id,obj)}
}
function dicLen(dic){
    var count=0;
    for(var key in dic){
        console.log(key+'='+dic[key]);
        count++;
    }
    return count
}
function newTimu(id,json,hideButton,addHr,parent=''){
    parent = parent !== undefined ? parent : ''
    addHr = addHr !== undefined ? addHr : true
    hideButton = hideButton !== undefined ? hideButton : false
    var type = json.type
    var o = new Object()
    o.temp = {
        main:$('<div id="'+id+'" class="type'+type+'"></div>'),
        subject:$('<div class="subject"></div>'),
        range:$('<div class="sourceRange"></div>'),
        info:$('<div class="info"></div>'),
        titleCon:$('<div class="titleContainer"></div>'),
        source:$('<p class="source"></p>'),
        title:$('<p class="title"></p>'),
        options:$('<div class="options"></div>'),
        btn:$('<button class="button-small button-pill button button-caution" id="showSingle-' + id + '" class="showSingleBtn">提交</button>'),
        ansCon:$('<div id="ansContainer" class="ansContainer noDisplay"></div>'),
        correct:$('<p style="display:inline;"><b>正确答案:</b></p><p class="correctAnswer"></p><br>'),
        explain:$('<p style="display:inline;"><b>解析: </b></p><p class="explain"></p><br>'),
        select:$('<select class="button-small button-rounded button"></select>'),
        subTitle:$('<div id=""></div>')
    }
    o.hideButton = hideButton
    o.parent = parent
    if(type!=='A3'&&type!=='PD'){
        o.temp.btn.bind("click",function (){
            showChoiceAnswer(id,type,json.answer)
        })
    }

    o.A = function () {
        this.temp.source.text(json.source)
        this.temp.title.text(json.title)
        this.temp.correct.nextAll('.correctAnswer').text(json.answer)
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)
        var options = formatAnsDic(json.choices)
        for(var k in options) {
            var label = '<label id="' + k + '"><input name="singelChoice-' + id + '" type="radio" value="' + k + '" />' + k + ':' + options[k] + '</label>'
            this.temp.options.append(label)
        }
        this.temp.titleCon.append(this.temp.source,this.temp.title)
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
        this.temp.main.append(this.temp.subject,this.temp.ansCon)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.A3 = function () {
        var subIDs = []
        var s = json.source*1;var e = json.source*1+json.sourceRange*1 -1
        this.temp.range.text('第 '+s+' 到 '+e+' 题')
        for(var i=0;i<json.title.length;i++){
            subIDs.push(id+'-'+i)
            if(json.explain[i]==undefined){
                json.explain[i] = '暂无解析'
            }
            var data = {
                "type":"A",
                "source":json.source+'-'+(i+1),
                "title":json.title[i],
                "answer":json.answer[i],
                "explain":json.explain[i],
                "choices":json.choices[i],
            }
            var newA = newTimu(id+'-'+i,data,true,false).A()
            render(id+'-'+i,'A',newA,this.temp.titleCon)
        }
        o.temp.btn.bind("click",function (){
            showChoiceAnswer(subIDs,type,json.answer)
        })
        this.temp.info.text(json.info)
        this.temp.subject.append(this.temp.range,this.temp.info,this.temp.titleCon)
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
        this.temp.main.append(this.temp.subject)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.B = function () {
        var s = json.source*1;var e = json.source*1+json.sourceRange*1 -1
        this.temp.range.text('第 '+s+' 到 '+e+' 题')

        var options = formatAnsDic(json.choices)
        for(var k in options){
            var label = '<li id="'+k+'">'+k+':'+options[k]+'</li>'
            this.temp.options.append(label)
            this.temp.select.append('<option value="'+k+'">'+k+'</option>')
        }
        for(var i=0;i<json.title.length;i++){
            var reg1 = /\(\)/g
            var text = json.title[i]
            if(reg1.test(text)){
                text = text.replace("()",this.temp.select.prop("outerHTML"))
            }else{
                text += this.temp.select.prop("outerHTML")
            }
            this.temp.subTitle.attr('id',id+'-'+i)
            this.temp.source.text(s+i)
            this.temp.subTitle.html(this.temp.source.prop("outerHTML")+text)
            this.temp.titleCon.append(this.temp.subTitle.prop("outerHTML"))
        }
        for(var i=0;i<json.answer.length;i++){
            this.temp.correct.nextAll('.correctAnswer').append('<p id="ans-'+id +'-'+i+'">'+(id+i)+':'+json.answer[i]+'</p>')
        }
        for(var i=0;i<json.explain.length;i++){
            this.temp.explain.nextAll('.explain').append('<p id="exp-'+id +'-'+i+'">'+(id+i)+':'+json.explain[i]+'</p>')
        }

        this.temp.subject.append(this.temp.range,this.temp.options,this.temp.titleCon)
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
        this.temp.main.append(this.temp.subject,this.temp.ansCon)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.C = function () {
        var s = json.source*1;var e = json.source*1+json.sourceRange*1 -1
        this.temp.range.text('第 '+s+' 到 '+e+' 题')

        var options = formatAnsDic(json.choices)
        for(var k in options){
            var label = '<li id="'+k+'">'+k+':'+options[k]+'</li>'
            this.temp.options.append(label)
            this.temp.select.append('<option value="'+k+'">'+k+'</option>')
        }
        for(var i=0;i<json.title.length;i++){
            var reg1 = /\(\)/g
            var text = json.title[i]
            if(reg1.test(text)){
                text = text.replace("()",this.temp.select.prop("outerHTML"))
            }else{
                text += this.temp.select.prop("outerHTML")
            }
            this.temp.subTitle.attr('id',id+'-'+i)
            this.temp.source.text(s+i)
            this.temp.subTitle.html(this.temp.source.prop("outerHTML")+text)
            this.temp.titleCon.append(this.temp.subTitle.prop("outerHTML"))
        }
        for(var i=0;i<json.answer.length;i++){
            this.temp.correct.nextAll('.correctAnswer').append('<p id="ans-'+id +'-'+i+'">'+(id+i)+':'+json.answer[i]+'</p>')
        }
        for(var i=0;i<json.explain.length;i++){
            this.temp.explain.nextAll('.explain').append('<p id="exp-'+id +'-'+i+'">'+(id+i)+':'+json.explain[i]+'</p>')
        }

        this.temp.subject.append(this.temp.range,this.temp.titleCon,this.temp.options)
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
        this.temp.main.append(this.temp.subject,this.temp.ansCon)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.X = function () {
        this.temp.source.text(json.source)
        this.temp.title.text(json.title)
        this.temp.correct.nextAll('.correctAnswer').text(json.answer)
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)
        var options = formatAnsDic(json.choices)
        for(var k in options){
            var label = '<label id="'+k+'"><input name="singelChoice-'+id+'" type="checkbox" value="'+k+'" />'+k+':'+options[k]+'</label>'
            this.temp.options.append(label)
        }

        this.temp.titleCon.append(this.temp.source,this.temp.title)
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
        this.temp.main.append(this.temp.subject,this.temp.ansCon)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.PD = function () {
        this.temp.source.text(json.source)
        this.temp.title.text(json.title)
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)
        var ans = ''
        if(json.answer=='T' || json.answer=='正确' || json.answer=='1' || json.answer=='√'){
            ans = '正确'
        }else if(json.answer=='F' || json.answer=='错误' || json.answer=='0' || json.answer=='×'){
            ans = '错误'
        }
        this.temp.correct.nextAll('.correctAnswer').text(ans)
        o.temp.btn.bind("click",function (){
            showChoiceAnswer(id,'A',ans)
        })
        this.temp.options.append('<label id="正确" style="display: inline;"><input name="singelChoice-'+id+'" type="radio" value="正确" />正确</label>' +
            '<label id="错误" style="display: inline;"><input name="singelChoice-'+id+'" type="radio" value="错误" />错误</label>')
        this.temp.titleCon.append(this.temp.source,this.temp.title)
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
        this.temp.main.append(this.temp.subject,this.temp.ansCon)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.TK = function () {
        this.temp.source.text(json.source)
        var form = $('<form id="form-'+id+'" class="title"></form>')
        var pos = json.pos
        var posReg = new RegExp(pos,'g')
        var posCount = json.title.match(posReg).length
        for(var i=0;i<posCount;i++){
            json.title = json.title.replace(pos,'<input name="'+id+'-'+i+'" id="'+id+'-'+i+'" type="text" form="form-'+id+'"/>')
        }
        form.html(json.title)
        this.temp.title.text(json.title)
        this.temp.correct.nextAll('.correctAnswer').text(json.answer)
        this.temp.explain.nextAll('.correctAnswer').text(json.explain)

        this.temp.titleCon.append(this.temp.source,form)
        this.temp.ansCon.append(this.temp.correct,this.temp.explain)
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
        if(!hideButton){this.temp.subject.append(this.temp.btn)}
        this.temp.main.append(this.temp.subject,this.temp.ansCon)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    o.MJ = function () {
        this.temp.source.text(json.source)
        this.temp.title.html(json.title + ':<span class="blur" tabindex="0" style="display:inline;outline=0;" onclick="">' + json.answer +'</span>')
        this.temp.titleCon.append(this.temp.source,this.temp.title)
        this.temp.subject.append(this.temp.titleCon,this.temp.options)
        this.temp.main.append(this.temp.subject)

        if(addHr){this.temp.main.append('<hr>')}
        return this.temp.main
    }
    return o
}
function formatAnsDic(d) {
    var c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    var dic = {}
    for(var i=0;i<c.length;i++){
        if(d?.[c[i]]||''.length>0){
            dic[c[i]] = d[c[i]]
        }
    }
    return dic
}
function showAns(id,type,correctAnswer){
    var s = new Object()
}
function showChoiceAnswer(id,type,correctAnswer){
    var subjectCon = $('#'+id)
    var titleCon = subjectCon.children('.subject').children('.titleContainer')
    var ansCon = subjectCon.children('.ansContainer')
    var answers = subjectCon.children('.subject').children('.options')
    console.log(correctAnswer)
    if(type==="A"){
        var correctAnsText = correctAnswer
        var choice = $('input[name="singelChoice-'+id+'"]:checked').val();
        console.log(choice)
        var showCorrect = answers.children('#'+correctAnsText)
        var showChoice = answers.children('#'+choice)
        $('#showSingle-'+id).addClass('noDisplay')
        ansCon.fadeIn(100)
        if(choice===correctAnsText){
            showCorrect.addClass('correct')
        }else{
            showCorrect.addClass('correct')
            showChoice.addClass('wrong')
        }
        setTimeout(function (){
            removeBackground(showChoice)
            removeBackground(showCorrect)
        }, 4000);

        setTimeout(function (){
            showCorrect.removeClass('no-background')
            showChoice.removeClass('no-background')
            showCorrect.removeClass('correct')
            showChoice.removeClass('wrong')
        }, 5000);
    }else if(type==='A3'){
        $('#showSingle-'+id).addClass('noDisplay')
        for(var i=0;i<id.length;i++){
            var subID = id[i]
            var mainID = subID.split('-')[0]
            console.log(subID)
            console.log(mainID)
            subjectCon = $('#'+ id[i])
            titleCon = subjectCon.children('.subject').children('.titleContainer')
            ansCon = subjectCon.children('.ansContainer')
            answers = subjectCon.children('.subject').children('.options')
            $('#showSingle-'+id).addClass('noDisplay')
            var correctAns= correctAnswer[i]
            //以下与A型题时一样的代码,知识用subID替换ID变量
            showChoiceAnswer(subID,'A',correctAns)
        }

    } else if(type==='B'){
        console.log(titleCon)
        titleCon.children('div').each(function (index,i){
            console.log(i)
            var subTitleID = $(i).attr('id')
            var ans = correctAnswer[index]
            var choice = $('#'+id+'-'+index).find("option:selected").text();
            $('#showSingle-'+id).addClass('noDisplay')
            console.log(choice)
            if(choice==ans){
                $('#'+id+'-'+index).addClass('correct')
            }else {
                $('#'+id+'-'+index).addClass('wrong')
                $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))

            }
            setTimeout(function (){
                $('#'+id+'-'+index).removeClass('correct')
                $('#'+id+'-'+index).removeClass('wrong')
            }, 5000);
        })
    } else if(type=="C"){
        console.log(titleCon)
        $('#showSingle-'+id).addClass('noDisplay')
        titleCon.children('div').each(function (index,i){
            console.log(i)
            var subTitleID = $(i).attr('id')
            var ans = correctAnswer[index]
            var choice = $('#'+id+'-'+index).find("option:selected").text();
            console.log(choice)
            if(choice==ans){
                $('#'+id+'-'+index).addClass('correct')
            }else {
                $('#'+id+'-'+index).addClass('wrong')
                $('<p class="answerTip">正确答案:'+ans+'</p>').appendTo($('#'+id+'-'+index))

            }
            setTimeout(function (){
                $('#'+id+'-'+index).removeClass('correct')
                $('#'+id+'-'+index).removeClass('wrong')
            }, 5000);
        })
    }else if(type=="X"){
        var correctAnsText = correctAnswer
        var choice = ""
        $('input[name="singelChoice-'+id+'"]:checked').each(function (){
            choice += $(this).val()
        })
        console.log(choice)
        console.log(correctAnsText)
        var btn = $('#showSingle-'+id).addClass('noDisplay')
        ansCon.fadeIn(100)
        for(var i=0;i<choice.length;i++){
            var showCorrect = answers.children('#'+correctAnsText[i])
            var showChoice = answers.children('#'+choice[i])
            if(correctAnsText.indexOf(choice[i])!=-1){
                showChoice.addClass('correct')
            }else{
                showChoice.addClass('wrong')
            }
        }
        for(var i=0;i<correctAnsText.length;i++){
            console.log(i)
            var showCorrect = answers.children('#'+correctAnsText[i])
            $('<p class="answerTip">✓</p>').appendTo(showCorrect)
        }
        answers.children('label').each(function (){
            var a = $(this)
            setTimeout(function (){
                removeBackground(a)
            }, 4000);
            setTimeout(function (){
                a.removeClass('no-background')
                a.removeClass('correct')
                a.removeClass('wrong')
            }, 5000);
        })
    }else if(type=="TK"){
        $('#showSingle-'+id).addClass('noDisplay')
        ansCon.fadeIn(100)
        var answers = correctAnswer
        console.log(answers[0])
        var form =$('#form-'+id).serializeArray()
        var myAns = []
        console.log(form[0]['value'])
        for(var i=0;i<form.length;i++){
            var input = $('#form-'+id).children('#'+id+'-'+i)
            if(answers[i] != form[i]['value']){
                $('<p class="wrong TKcheck">'+answers[i]+'</p>').insertAfter(input)
            }else{
                $('<p class="correct TKcheck">'+answers[i]+'</p>').insertAfter(input)
            }
        }
    }
}
function removeBackground(obj){
    obj.addClass('no-background')
}