试图制作一个问答程序,一旦用户按下“下一个问题”按钮,它就会显示问题2。我提供了HTML,javascript和style.css文件来显示我的工作。问题不在于代码可见,而是单击按钮不起作用
我的代码:
function question2() {
document.getElementById("Question2_visible").style.visibility =
"visible";
}
#Question2_visible {
visibility: hidden;
}
<!DOCTYPE html>
<html>
<head>
<title>Welcome!</title>
<link href="style.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<script src="main.js"></script>
</head>
<body>
<h1>Answer these questions:</h1>
<form id="quiz" name="quiz">
<p class="questions">What is your name?</p>
<input id="textbox" type="text" name="question1">
<input id="button" type="button" value="Next Question pls!" onclick=" question2();">
<div id="Question2_visible">
<p class="questions">What is your age??</p>
<input type="radio" id="mc" name="question2" value="<18"> more
<br>
<input type="radio" id="mc" name="question2" value=">18"> less
<br>
</div>
</form>
</body>
</html>
答案 0 :(得分:2)
您的name="question2"
会干扰question2
功能。
如果名称冲突,请调用窗口对象上的函数:
onclick="window.question2()"