[英]I am trying to find out why my value for the radio button is shown on the console but not on the browser when I run the following code?
for (var i = 0; i < allQuestions[n].choices.length; i++) {
var input = document.createElement("input");
input.type = "radio";
input.name = "choices";
input.value = "choice" + i;
var answer = document.getElementById("answer");
var option = document.createTextNode(allQuestions[n].choices[i]);
input.appendChild(option);
answer.appendChild(input);
}
http://jsfiddle.net/slopeofhope81/g9V9d/ http://jsfiddle.net/slopeofhope81/g9V9d/
input
elements cannot have children : input
元素不能有孩子 :
The input element is a void element.
输入元素是一个void元素。 An input element must have a start tag but must not have an end tag.
输入元素必须具有开始标签,但不能具有结束标签。
A void element is an element whose content model never allows it to have contents under any circumstances.
void元素是其内容模型在任何情况下都不允许其内容的元素。 Void elements can have attributes.
空隙元素可以具有属性。
You can add the text after the input: 您可以在输入之后添加文本:
var option = document.createTextNode(allQuestions[n].choices[i]);
answer.appendChild(input);
answer.appendChild(option);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.