我正在创建一段 Javascript 代码,您可以在其中创建具有多个答案的多个问题。问题数量最多为 20 个。当我单击“添加问题”时,它会添加一个带有两个答案的问题。当我填写一些输入字段并单击“添加问题”时,它会清空我的所有文本字段。这怎么可能?
var fields = 0;
var qAmount = 0;
var array = new Array();
function addInput() {
if (fields != 2) {
qAmount++;
var element = document.getElementById('texty');
element.innerHTML += "" +
"<label>Question " + qAmount + "</label><span class='field'><input type='text' class='longinput' name='question" + qAmount + "' /></span>" +
"<span class='field'><input type='radio' name='question" + qAmount + "-correctanswer' value='answer" + qAmount + "-1' /> <input type='text' name='answer" + qAmount + "-1'> Answer 1</input></span>" +
"<span class='field'><input type='radio' name='question" + qAmount + "-correctanswer' value='answer" + qAmount + "-2' /> <input type='text' name='answer" + qAmount + "-2'> Answer 2</input></span>" +
"<div id='a" + qAmount + "'></div><br/>" +
"<span class='field'><a style='cursor: pointer' onclick='addAnswer(" + qAmount + ")'>Add answer</a></span><br /><br />";
fields += 1;
array[qAmount] = 2;
}
}