cuốn sách gpt4 ai đã làm

javascript - 单选按钮选择时显示 "Correct"

In lại Tác giả: Walker 123 更新时间:2023-11-28 04:14:26 28 4
mua khóa gpt4 Nike

我对 JS 和 HTML5 有点陌生。我正在创建一个简单的测验,只是为了好玩。我知道需要使每个问题都能够独立于其他问题而被标记为“正确”。我如何通过 JS,甚至 CSS/HTML5 来做到这一点?我感觉我需要更改 jquery 文件,但我对如何操作有点困惑。该测验运行完美,正是我想要的方式,但当用户选择答案时,我想显示正确或错误。基本上,当在浏览器中拉出测验时,用户将从每个问题中选择一个答案,当选择正确答案时,我想显示“正确”一词。

依次是我的game.js、CSS 和索引

if (jQuery) {
var checkAnswers = function() {
var answerString = "";
var answers = $(":checked");
answers.each(function(i) {
answerString = answerString + answers[i].value;
});
$(":checked").each(function(i) {
var answerString = answerString + answers[i].value;
});
checkIfCorrect(answerString);
};

var checkIfCorrect = function(theString) {
if (parseInt(theString, 16) === 811124566973) {
$("body").addClass("correct");
$("h1").text("You Win!");

}
};

$("#question1").show();
};
if (impress) {
$("#question2").show();
};
if (atom) {
$("#question3").show();
};
if (createjs) {
$("#question4").show();
};
if (me) {
$("#question5").show();
};
if (require) {
$("#question6").show();
};
if ($().playground) {
$("#question7").show();
};
if (jaws) {
$("#question8").show();
};
if (enchant) {
$("#question9").show();
};
if (Crafty) {
$("#question10").show();
};
thân hình {
margin-left: 50px;
}

#question1,
#question2,
#question3,
#question4,
#question5,
#question6,
#question7,
#question8,
#question9,
#question10 {
hiển thị: không có;
}

vải vẽ {
hiển thị: không có;
}

.correct {
background-color: #24399f;
màu sắc: trắng;
}

#question1 {
background-color: #EBF5D1;
}

#question2 {
background-color: #E0F0D4;
}

#question3 {
background-color: #D6EBD6;
}

#question4 {
background-color: #CCE6D9;
}

#question5 {
background-color: #C2E0DB;
}

#question6 {
background-color: #B8DBDE;
}

#question7 {
background-color: #ADD6E0;
}

#question8 {
background-color: #A3D1E3;
}

#question9 {
background-color: #99CCE6;
}

#question10 {
background-color: #8FC7E8;
}



<đầu>

Quiz




Quiz




Which is not a main file type that we use to make websites?













A JavaScript object is wrapped by what charaters?













Moles are which of the following?













In Japanese "か" is prounounced...













The gravitational constant on earth is approximately...













45 (in base 10) is what in binary (base 2)?













4
<< 2=. ..













Given the lengths of two sides of a right triangle (one with a 90 degree angle), how would you find the hypotenuse?













True or False: All games must run at at least 60 frames per second to be any good.









Using a server can help you to...

























Xem sitemap của VNExpress

câu trả lời hay nhất

有两种可能的方法:

  1. 将各个答案存储在 JS 中,并根据这些答案检查所选单选的值。
  2. 将问题的答案存储在数据库中,并向服务器发出请求,根据正确答案验证用户输入。

后者是推荐的解决方案,因为它会让用户看不到您的答案,但如果不重要,您可以使用前一种方法。

通过方法 1 可能的解决方案:

For each radio input create data attributes (question & correct).Now for each selection, check 'question' attribute value and fetch its answer.If it matches, display "Correct" message below the question, else display "Incorrect"

关于javascript - 单选按钮选择时显示 "Correct",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45989965/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress