Причина, по которой не будет отображаться потому, что вы заменить лейбла внутреннийHTML в
вопросPool [текущийQuestion] .соты [i] + <br>.
, когда вы добавляете радио в ярлыке, innerHTML лейбла стал "< вход > ... </вход >" , но тогда вы просто заменить его в
questionPool [currentQuestion] .choices [я] + "<br> ".
просто Подведите label.innerHTML = ... перед label.appendChild может решить вашу ситуацию.
вот немного изменить ответ, не используя innerHTML и внешнийHTML.
function displayQuestion() {
var question = document.getElementById("question"),
currentQuestion = 0,
numberOfChoices = questionPool[currentQuestion].choices.length;
question.textContent = questionPool[currentQuestion].question;
question.appendChild(document.createElement('br'));
for(var i=0; i < numberOfChoices; i++) {
var label = document.createElement('label'),
radio = document.createElement('input'),
textNode= document.createTextNode(questionPool[currentQuestion].choices[ i]),
lineBreakNode = document.createElement("br");
radio.setAttribute('type', 'radio');
radio.setAttribute('name', 'choice');
radio.setAttribute('value', 'questionPool[currentQuestion].choices[i]');
label.appendChild(radio);
label.appendChild(textNode);
label.appendChild(lineBreakNode);
question.appendChild(label);
}
}
http://jsfiddle.net/vadjn2an/9/
иметь радиошоу перед лейблом, я использую label.outerHTML вводить его innerHTML лейбла
function displayQuestion() {
var question = document.getElementById("question");
var currentQuestion = 0;
var numberOfChoices = questionPool[currentQuestion].choices.length;
question.textContent = questionPool[currentQuestion].question;
question.appendChild(document.createElement('br'));
for(var i=0; i < numberOfChoices; i++) {
var label = document.createElement('label');
var radio = document.createElement('input');
radio.setAttribute('type', 'radio');
radio.setAttribute('name', 'choice');
radio.setAttribute('value', 'questionPool[currentQuestion].choices[i]');
label.innerHTML = radio.outerHTML + questionPool[currentQuestion].choices[i] + "<br/>";
question.appendChild(label);
}
}
http://jsfiddle.net/vadjn2an/8/
Если проблема в том, что не появляется кнопка радио, чем is't, потому что после добавления его маркировать вы делаете: label.innerHtml =». .."Ведьма переписывает you'r кнопку – Rasalom
@Rasalom Я сделал заказ, как это сейчас, но все еще есть ошибки, – Yumiko
@Rasalom label.innerHTML = questionPool [currentQuestion] .choices [я] +."
«; этикетки. appendChild (radio); question.appendChild (label); – Yumiko