如何使用javascript在mcq中添加选项
我正在尝试创建能够创建mcq的程序。下面是我的代码如何使用javascript在mcq中添加选项,javascript,html,Javascript,Html,我正在尝试创建能够创建mcq的程序。下面是我的代码 <p>how many mcq choice you need?</p> <input type="text" id="question"></input> 您需要多少mcq选择 现在我尝试使用javascript从文本框中检索输入。如果输入为4,它将出现 a b c d 要实现这一点,javascript看起来会是什么样子?试试这样 function check () { if (d
<p>how many mcq choice you need?</p>
<input type="text" id="question"></input>
您需要多少mcq选择
现在我尝试使用javascript从文本框中检索输入。如果输入为4,它将出现
a
b
c
d
要实现这一点,javascript看起来会是什么样子?试试这样
function check () {
if (document.getElementById('question').value == 4) {
document.getElementsByTagName('p')[0].innerHTML += "a </br> b </br> c </br> d </br>"
}
}
功能检查(){
if(document.getElementById('question')。值==4){
document.getElementsByTagName('p')[0].innerHTML+=“abcd”
}
}
在更改事件中绑定此函数。尝试此操作
<script type="text/javascript">
function CreateMCQ(){
document.getElementById('option').innerHTML = "";
var input = document.getElementById('question').value ;
for(var i = 0;i<input;i++){
document.getElementById('option').innerHTML += "<input type='radio'>"+"option "+(i+1)+"<br/> ";
}
}
</script>
函数CreateMCQ(){
document.getElementById('option').innerHTML=“”;
var输入=document.getElementById('question')。值;
对于(var i=0;我你试过这样做吗?为什么投反对票?我也有一把小提琴
<p>how many mcq choice you need?</p>
<input type="text" id="question"></input>
<input type="submit" value="Create" onclick="CreateMCQ();" />
<div id="option"></div>