JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(十三)自動答題

前文

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(一)答案獲取

Spring Boot——易班優課YOOC課羣在線測試自動答題解決方案(二)答案儲存

Spring Boot——易班優課YOOC課羣在線測試自動答題解決方案(三)答案查詢

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(四)答案顯示

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(五)簡單腳本

Spring Boot——易班優課YOOC課羣在線測試自動答題解決方案(六)後端改造

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(七)隨機答案

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(八)功能面板

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(九)ID標籤

Vue + Element UI + Spring Boot——易班優課YOOC課羣在線測試自動答題解決方案(十)問題管理頁面

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(十一)恢復右鍵、選擇和複製

JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(十二)腳本整合

輔助工具

正則表達式代碼生成工具 

解決方案

注:需要先從雲端加載答案 

加載答案參考:JavaScript——易班優課YOOC課羣在線測試自動答題解決方案(四)答案顯示

    var ansElements = Array.from(document.getElementsByClassName('the-ans'))
    let pattern=/\u6b63\u786e\u7b54\u6848\uff1a(.*)/
    ansElements.forEach(ansEle=>{
        let ans=ansEle.children[0].innerText.trim()
        if(pattern.test(ans)){
            var answers=pattern.exec(ans)[1]
            console.log(answers)
            let parentNode=ansEle.parentNode
            let question_id=parentNode.id.split('-')[1]
            answers.split('、').forEach(answer=>{
                if(/[A-Z]/.test(answer)){
                    let li_Eles=parentNode.getElementsByTagName('li')
                    let li_Ele=li_Eles[answer.charCodeAt(0)-65]
                    let input_id=li_Ele.dataset.questionName+"_"+li_Ele.dataset.questionValue
                    let Ele=document.getElementById(input_id)
                    if(Ele.type==="radio"){
                        Ele.checked=true;
                    }else if(Ele.type==="checkbox"){
                        Ele.checked=true;
                    }
                    //頁面方法
                    choiceAnswerData($(document.getElementById('question-'+question_id)))
                }else{
                    let input_id=question_id+"_" + (answers.indexOf(answer) + 1)
                    let Ele=document.getElementById(input_id)
                    Ele.value=answer
                    //頁面方法
                    inputAnswerData($(document.getElementById('question-'+question_id)))
                }
            })
            let questionTag=document.getElementById(question_id)
            questionTag.classList.add('done')
        }
    })

添加一個按鈕 

    var question=Array.from(document.getElementsByClassName('question-board'))
    var autoAnswerButton=document.createElement('a')
    autoAnswerButton.id="auto-answer-submit"
    autoAnswerButton.href="javascript:;"
    autoAnswerButton.innerText="自動答題"
    autoAnswerButton.style="margin-left: 0px;margin-top: 10px;"
    autoAnswerButton.title="答案自動選擇"
    autoAnswerButton.οnclick=()=>{
        autoAnswer()
        //頁面方法
        xAlert('提示','答案自動選擇完畢,請自行檢查填空題部分')
    }
    releaseButton.appendChild(autoAnswerButton)

運行結果

參考文章 

https://blog.csdn.net/zzti_erlie/article/details/89842391

https://www.runoob.com/regexp/regexp-syntax.html

https://www.cnblogs.com/ChengDong/articles/3771880.html

https://zhuanlan.zhihu.com/p/33335629

https://www.cnblogs.com/tangyongle/p/7499522.html

https://zhidao.baidu.com/question/495418166779664644.html

https://jingyan.baidu.com/article/0320e2c1bd21b25b86507b0d.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章