【发布时间】:2013-06-22 19:51:50
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<Title> Title: My Quiz </title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div>
<span id="question">Welcom to my Game hit next to play...</span>
</br>
<span id="answer" >possible answers will go here...</span>
</br>
<button id ="up"> next </button>
</div>
<script>
var allQuestions = [["Who is Prime Minister of the United Kingdom?","What is my favourite colour?"], [["David Cameron", "Gordon Brown", "Winston Churchill", "Tony Blair"],["red","blue","green","another"]], [0,1]];
var questionIndex = 0
$("#up").on("click", function () {
questionIndex+=1
$("#question").text("questionIndex = "+ questionIndex + "--Question " + questionIndex +": " + allQuestions[0][questionIndex-1])
});
//$("#up").on("click", function () {
//for(i=0;i<4;i++){
//$("#answer").text("<input type="radio" name="group1" value="Milk">" +allQuestions[1][questionIndex-1][0]+ "<br>")
//}
//});
</script>
</body>
</html>
如何将“span id="answer"" 更改为类似
<input type="radio" name="colour" value="blue">Blue<br>
<input type="radio" name="colour" value="red">Red<br>
<input type="radio" name="colour" value="green">Green<br>
<input type="radio" name="colour" value="another">Another<br>
我想要做的是将'span id="answer"' 更改为单选按钮,然后按下下一组答案将显示。这已经适用于'span id =“question”'(需要整理一下)。
【问题讨论】:
-
所有答案中的重要一点是,您必须使用
.html()将HTML 注入#answer <span> -
感谢您的建议。这有很多值得深思的地方,我会解决它们的。 tks
标签: jquery button radio-button