从单选按钮中获得值,一旦检查到最终分数
get value from radio button once checked to tally up final score
我正在与单选按钮进行多项选择测验,我想在选中单选按钮后获得价值,并在结束时给出最终分数。例如"1 out of 5 correct"
引用
> > $(document).ready(function() { > var counter = 0; > var score = 0; > > > var quizQuestions = [{ > question: "In what year was America founded ?", > choices: ["1775", "1776", "1801", "1492"], > answer: 1 > }, { > question: "Who did not sign the Declaration of Independence ?", > choices: ["George Wasington", "Ben Franklin", "John Hancock", "Thomas Jefferson"], > answer: 0 > }, { > question: "Who was the only president to serve more than two terms?", > choices: ["George Washington", "Woodrow Wilson", "Franklin Delano Roosevelt", "James Madison"], > answer: 2 > }, { > question: "In what year did America land on the moon ?", > choices: ["1969", "1965", "1970", "1968"], > answer: 0 > }, { > question: "Which country did America buy the Louisiana Purchase from ?", > choices: ["England", "Spain", "Germany", "France"], > answer: 3 > }] > > $("#start").click(function() { > $("#start").hide() > $("#next").show() > }) > > $("#next").on("click", function() { > > $(".choices, .questions").empty(); > > function incrementCounter() { > $("#count").text(counter); > }; > > $(".questions").append("<h2>" + quizQuestions[counter].question + "</h2>") > > for (var i = 0; i < quizQuestions[counter].choices.length; i += 1) { > $(".choices").append("<ul>" + "<input type='radio'/>" + quizQuestions[counter].choices[i] + "</ul>") > } > > incrementCounter(); > counter++ > > }) > > > }); > >
> > body { > background-image: url("../img/american-flag.jpg"); > background-repeat: no-repeat; > background-size: 100% 100%; > } > html, > body { > min-height: 100%; > } > .quiz-app { > position: relative; > width: 400px; > height: 400px; > background-color: white; > border-style: solid; > margin: 0 auto; > top: 200px; > text-align: center; > } > h1 { > color: orange; > } > #start { > margin-top: 70px; > width: 70px; > border-radius: 5px; > bottom: 150px; > } > #next { > display: none; > margin-top: 70px; > width: 70px; > border-radius: 5px; > bottom: 150px; > } > .questions { > text-align: center; > margin-left: 25px; > margin: 0 auto; > bottom: 120px; > color: red; > } > .choices { > display: block; > bottom: 100px; > } > #count { > width: 50px; > height: 20px; > text-align: bottom; > } > >
> > <!DOCTYPE html> > <html> > > <head> > <meta charset="UTF-8"> > <title>Quiz Time</title> > <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js" > charset="utf-8"></script> > <script src="js/jquery-1.11.3.min.js"></script> > <script src="js/jquery-1.11.3.js"></script> > <script src="js/app.js"></script> > <link rel="stylesheet" href="css/app.css"> > </head> > > <body> > <!--______________________________________________________BEGIN APP--> > <div class="quiz-app"> > <h1 class="title">History Quiz</h1> > > <div class="questions"></div> > > <div class="choices"> > </div> > > <button id="start">Start</button> > <button id="next">Next</button> > <span id="count"></span> > </div> > > </body> > <!--______________________________________________________END APP--> > > </html> > >
这是你要找的吗?
$(".choices input:radio").on("click", function () {
alert('test');
});
相关文章:
- 如何设置第一个子元素's的单选按钮已在轨道上检查4
- vue-js-单选按钮won't默认情况下使用v-model属性进行检查
- 如何重置剑道MVVM单选按钮's已检查状态
- html单选按钮检查问题
- 检查JavaScript中的单选按钮
- JS中的单选按钮检查不起作用
- 当我单击它时,没有检查带有数据切换=选项卡的单选按钮
- 循环遍历单选按钮(20 组,每组 3 个),并检查是否选中了每个组
- 更改单选按钮检查的值的字体大小
- Wooccommerce单选按钮检查jquery
- 通过单选按钮检查提交表单
- 使用if-else-if-true检查(验证)单选按钮如果未检查则无警报必须检查警报
- 我的单选按钮没有从foreach循环中获得值,表单验证返回'必填字段'即使已检查
- 如何检查是否没有选中任何单选按钮
- 如何使用javascript检查id字段为空的单选按钮
- 如何检查一组单选按钮是否全部选中
- 设置第一个单选按钮是在车把模板中检查的
- 对用户交互进行单选按钮检查
- 如何将mysql值附加到单选按钮并进行检查
- 在允许用户进入下一部分之前,在表单验证中检查是否单击了某个选项(单选按钮)