私のクイズの最初の質問に残りの質問とは独立したラジオボタンがあるのはなぜかと思っていますが、質問1の後にすべての質問がラジオボタングループとして機能しますか? これはjavascriptのです:なぜこれらのラジオボタンはJavaScriptを使用して動作しますか?
window.onload = getQuizXml;
function getQuizXml() {
var quiz = new XMLHttpRequest();
quiz.onreadystatechange = function() {
if (quiz.readyState == 4 && quiz.status == 200) {
searchQuiz(quiz);
}
};
quiz.open("GET", "FinalQuiz.xml", true);
quiz.send();
}
function searchQuiz(quiz) {
var i;
//get data as xml file
var xmldoc = quiz.responseXML;
var test = "<form id = 'test'>";
//start table
//process data by record
var x = xmldoc.getElementsByTagName("question");
var errorMessage = "Error, Well does not exist.";
for (i = 0; i < x.length; i++) {
var questionNumber = x[i].getElementsByTagName("qnumber")[0].childNodes[0].nodeValue;
var questionTitle = x[i].getElementsByTagName("qtitle")[0].childNodes[0].nodeValue;
var a = x[i].getElementsByTagName("a")[0].childNodes[0].nodeValue;
var b = x[i].getElementsByTagName("b")[0].childNodes[0].nodeValue;
var c = x[i].getElementsByTagName("c")[0].childNodes[0].nodeValue;
var d = x[i].getElementsByTagName("d")[0].childNodes[0].nodeValue;
test += "<br>" + questionNumber + "." +
"<br>" +
questionTitle +
"<br><br>" +
"a)<input type='radio' value='a' name ='question'>" + a +
"<br>" +
"b)<input type='radio' value='b' name ='question'>" + b +
"<br>" +
"c)<input type='radio' value='c' name ='question'>" + c +
"<br>" +
"d)<input type='radio' value='d' name ='question'>" + d +
"<br></form>";
document.getElementById("displayquiz").innerHTML = test;
}
}
、これは、XMLのサンプルです:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE finalquiz SYSTEM "FinalQuiz.dtd" >
<finalquiz>
<question>
<qnumber>1</qnumber>
<qtitle>In a switch statement, the ________ case clause is used to process exceptional conditions and is usually listed last.</qtitle>
<a>break</a>
<b>default</b>
<c>else</c>
<d>then</d>
</question>
<question>
<qnumber>2</qnumber>
<qtitle>The technique of developing and maintaining a large program by constructing it from small, simple pieces is called ________.</qtitle>
<a>divide and conquer</a>
<b>modular programming</b>
<c>multitasking</c>
<d>multiprogramming</d>
</question>
<question>
<qnumber>3</qnumber>
<qtitle>All variables declared in function definitions are ________.</qtitle>
<a>global variables</a>
<b>static variables</b>
<c>constant variables</c>
<d>local variables</d>
</question>
ラジオボタンは 'name'属性を使用してグループ化されます。私は質問1が残りの部分とは別のグループにある理由は何もわかりません。 – Barmar
あなたのラジオボタンはすべて 'name = 'question''を持っているので、それらは1つのグループでなければなりません。 – Barmar
ところで、ループが終了した後ではなく、ループを通過するたびに 'innerHTML'を割り当てるべきです。 – Barmar