这是我的代码:
$(document).ready(function () {
$("input").focus(function () {
$(this).css('outline-color', '#559FFF');
$(this).blur(function () {
$(this).css("outline-color", "#FF0000");
});
});
$("input").click(function () {
var value = $(this).val(function () {
$(this).html("");
});
});
$(".awesome").click(function () {
var toStore = $("input[name=name]").val();
if (!/^[A-Za-z]+ [A-Za-z]+$/.test(toStore)) {
alert("You Must Put a Valid Name");
} else {
$("#contain").children().fadeOut(1000);
$("#contain").delay(1000).queue(function () {
$("#contain").append("<h1>Welcome to My Quiz : " + toStore + "</br>" +
"Youll Get 10 Questions To Answer </br> " +
"Here Is the First One:Who is Prime Minister of the United Kingdom? </h1>");
var allQuestions = {
outquestions:{
question1 : { quest: "Who is Prime Minister of the United Kingdom?",
choices: ["David Cameron","Gordon Brown","Winston Churchill","Tony Blair"],
correctAnswer: "David Cameron"},
question2 : { quest: "whats dad name?",
choices: ["David ","Gordon ","Winston ","Tony "],
correctAnswer: "David"}
},
correctAnswers: 0
};
var outquestions = allQuestions["outquestions"];
for (var question in outquestions) {
$("#contain").append("<p>(outquestions[question][quest]</p>");
for (var choice in outquestions[question]["choices"]) {
$("h1").append("<form><input type='radio' name=question value=choice></form>");
}
}
$("#contain").append("<form><input type='submit' value='submit'></form>");
$("#contain").on("click", "input[name=submit]", function () {
});
});
}
});
});
我希望本节循环遍历问题并在以下内容之间写:
var outquestions = allQuestions["outquestions"];
for (var question in outquestions) {
$("#contain").append("<p>(outquestions[question][quest]</p>");
for (var choice in outquestions[question]["choices"]) {
$("h1").append("<form><input type='radio' name=question value=choice></form>");
}
}
$("#contain").append("<form><input type='submit' value='submit'></form>");
之后,我想要所有已循环的问题的答案任何给定的时间来显示单选按钮和单选按钮按钮的值,我得到你在图片中看到的内容。这里有什么问题?