我目前正在尝试为老师构建一个测验模板,以供学生回答问题。我有一个 javascript 函数来显示所需数量的问题,一个 html div 包含所有必要的输入框,以及一个 javascript 函数来切换此 div。我的问题是我不知道如何将它们放在一起。这是我到目前为止所拥有的,我不知道为什么它不起作用。
var wrapper = document.getElementById("myHTMLWrapper");
var number = prompt("Enter the number of questions");
var myHTML = '';
for (var i = 0; i < number; i++) {
myHTML += '<span class="test">Question ' + (i + 1) +
'</span><br/><br/>'
<input type="button" value="Show DIV" id="bt" onclick="toggle(cont)">
}
wrapper.innerHTML = myHTML
function toggle(cont) {
var cont = document.getElementById('cont');
if (cont.style.display == 'block') {
cont.style.display = 'none';
document.getElementById(ele.id).value = 'Show DIV';
}
else {
cont.style.display = 'block';
document.getElementById(ele.id).value = 'Hide DIV';
}
};
<form id='namennumber' action="includes/dbquestions.php" method="post">
<label for="quizname"><b>Quiz name</b></label>
<input name="quizname" type="text" placeholder="Enter quizname" required>
<div id="myHTMLWrapper">
</div>
</form>
<div style="border:solid 1px #ddd; padding:10px; display:none;" id="cont">
<div id="questionform" class="modal">
<label for="question"><b>Enter a question</b></label>
<input name="question" type="text" placeholder="Enter a question" value="question" required>
<br>
<label for="answer1">Possible answer A</label>
<input type="text" name="answer1" placeholder="Enter a possible answer" value="answer1" required>
<br>
<label for="answer2">Possible answer B</label>
<input type="text" name="answer2" placeholder="Enter a possible answer" value="answer2" required>
<br>
<label for="answer3">Possible answer C</label>
<input type="text" name="answer3" placeholder="Enter a possible answer" value="answer3" required>
<br>
<label for="answer4">Possible answer D</label>
<input type="text" name="answer4" placeholder="Enter a possible answer" value="answer4" required>
<br>
</div>
</div>
炎炎设计
相关分类