// 总问题数 防止越界
for (i = 0; i <= document.querySelectorAll(".test > table > tbody").length -1 ; i++) {
question_text = (document.querySelectorAll(".test > table")[i].querySelector("thead > tr > th > label").textContent.substring(document.querySelectorAll(".test > table")[i].querySelector("thead > tr > th > label").textContent.indexOf("、") + 1));
console.log("Q:" + question_text)
if (correct_ans.hasOwnProperty(question_text)) {
// 答案选项
for (j = 1; j <= document.querySelectorAll(".test > table")[i].querySelector(" tbody").childElementCount; j++) {
if (correct_ans[question_text] == document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()) {
document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td > label > input").click()
ans_text = document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()
sub_ans[question_text] = ans_text;
console.log("Already have correct answer for this question -> " + ans_text)
break;
}
}
} else if (wrong_ans.hasOwnProperty(question_text)) {
for (j = 1; j <= document.querySelectorAll(".test > table")[i].querySelector(" tbody").childElementCount; j++) {
if (wrong_ans[question_text].indexOf(document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()) == -1) {
document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td > label > input").click()
ans_text = document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(" + j + ") > td ").textContent.trim()
sub_ans[question_text] = ans_text;
console.log("Only have wrong answer for this question, try -> " + ans_text)
break;
}
}
} else {
document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(1) > td > label > input").click();
ans_text = document.querySelectorAll(".test > table")[i].querySelector(" tbody > tr:nth-child(1) > td ").textContent.trim()
sub_ans[question_text] = ans_text;
console.log("First time meet this question, try -> " + ans_text)
}
};