gpt4 book ai didi

javascript - 我试图找出为什么当我运行以下代码时,单选按钮的值显示在控制台上而不是浏览器上?

转载 作者:行者123 更新时间:2023-11-28 08:29:49 24 4
gpt4 key购买 nike

    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/

最佳答案

input elements cannot have children :

The input element is a void element. An input element must have a start tag but must not have an end tag.

and

A void element is an element whose content model never allows it to have contents under any circumstances. Void elements can have attributes.

您可以在输入后添加文字:

var option = document.createTextNode(allQuestions[n].choices[i]);
answer.appendChild(input);
answer.appendChild(option);

DEMO

关于javascript - 我试图找出为什么当我运行以下代码时,单选按钮的值显示在控制台上而不是浏览器上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22003041/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com