测试链接:https://www.wenjuan.group/s/iQFzQz6/
var questionpageIdListname;
var question;
var question_type;
var optionGroupListProcessed;
// 单选多选选择
function answerParse(i, question) {
var lists = document.querySelectorAll('.question-box');
lists[i - 1].querySelectorAll("span input")[question].click();
}
// 填空
function textareaValue(number, newText) {
try {
var lists = document.querySelectorAll('.question-box');
var inputDom = lists[number - 1].querySelector('textarea');
inputDom.value = newText;
inputDom.dispatchEvent(new Event('input'));
inputDom.dispatchEvent(new Event('click'));
inputDom.dispatchEvent(new Event('focus'));
inputDom.dispatchEvent(new Event('blur'));
} catch (err) {
console.log(err);
}
}
let student = {"name":"小k","xuehao":"128","classname":"2023班"}; // 前三题自定义
window.scrollTo(0, document.body.scrollHeight);
questionpageIdListname = Object.values(window.globalData.project.pageList)[0];
// 处理问题
for (var i = 0; i < questionpageIdListname.question_list.length; i++) {
var theTitle = i + 1;
question = questionpageIdListname.question_list[i];
question_type = question.question_type;
if (question_type == 6) {
if (i == 0) {
textareaValue(theTitle, student.name);
}
if (i == 1) {
textareaValue(theTitle, student.xuehao);
}
if (i == 2) {
textareaValue(theTitle, student.classname);
}
}
if ([2, 3].includes(question_type)) {
optionGroupListProcessed = question.optionGroupListProcessed[0];
for (var d = 0; d < optionGroupListProcessed.option_list.length; d++) {
var duooption = optionGroupListProcessed.option_list[d].custom_attr.is_correct;
if (duooption == 1) {
answerParse(theTitle, d);
}
}
}
}```
|