var text = "";
for (var x = 0; x < questions.length; x++)
{
text += (x+1) + ". " + questions[x] + "<br>";
}
document.getElementById("q").innerHTML = text;
我有一系列问题(大小= 5)和每个问题的5个答案数组。
var ans1 = ["answer","answer","answer","answer"];
var ans2 = ["answer","answer","answer","answer"];
var ans3 = ["answer","answer","answer","answer"];
var ans4 = ["answer","answer","answer","answer"];
var ans5 = ["answer","answer","answer","answer"];
var questions = ["q1", "q2", "q3", "q4", "q5"];
通过我的代码,我只是显示了5个问题。我无法弄清楚如何为每个问题插入一组单选按钮。帮助
(我已经在java上做过但我无法将其转换为javascript。我是新手:|) 提前致谢
答案 0 :(得分:0)
您可以通过创建&#39;输入来创建广播选项。元素通过DOM
var input = document.createElement("input");
您可以通过设置类型属性
来进行无线电类型输入input.type = "radio";
您还可以设置输入值
input.value = ans1[0];
这里有一个小小的细节:https://jsfiddle.net/0gw1ar21/2/