- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
对花生酱和果冻进行简单的多项选择、简短回答和多项 react 测验:)。我想做的是,当用户单击“提交”按钮时,它会显示正确或错误答案的数量。另外,问题旁边会显示他们选择的选择是正确还是不正确,例如在多项选择问题上,如果他们选择正确的答案(果冻),那么它会说“正确!”在该选项旁边。现在,当我单击“提交”时,什么也没有发生,不知道为什么,我以为它会弹出一个金额正确的警报,但什么也没有发生。我确信我错过了一些非常简单的东西,但由于某种原因它没有为我弹出,所以任何帮助将不胜感激。谢谢!
<!DOCTYPE html>
<html lang="en">
<head>
<title>
How to make a proper Peanut Butter and Jelly
</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script src = "scripts/main.js"></script>
</head>
<body>
<header>
</header>
<main>
<form id = "quiz" name = "quiz">
<p>what item do you use to spread peanut butter on the bread?</p>
<input id = "textbox" type = "text" name = "question1">
<p>what is one ingrediant of peanut butter and jelly sandwich?</p>
<input type = "radio" id = "mc" name = "question2" value = "cheese"> cheese <br>
<input type = "radio" id = "mc" name = "question2" value = "bacon"> bacon <br>
<input type = "radio" id = "mc" name = "question2" value = "jelly"> jelly <br>
<p>which of the following are correct ingredients required to make a Peanut Butter and Jelly sandwich?</p>
<input type = "checkbox" id = "mc" name = "question2" value = "bread"> bread <br>
<input type = "checkbox" id = "mc" name = "question2" value = "cheese"> cheese <br>
<input type = "checkbox" id = "mc" name = "question2" value = "peanut butter"> peanut butter <br>
<input type = "checkbox" id = "mc" name = "question2" value = "jelly"> jelly <br>
<input type = "checkbox" id = "mc" name = "question2" value = "toothpaste"> toothpaste <br>
<br>
<input id = "button" type = "button" value = "Submit Quiz" onclick = "check():">
<br>
</form>
</main>
<footer>
</footer>
</body>
JavaScript代码
function src(){
var question1 = document.quiz.question1.value;
var question2 = document.quiz.question2.value;
var question3 = document.quiz.question3.value;
var correct = 0;
var incorrect = 0;
if (question1 == "knife")
{
alert("correct!");
correct++;
}
else{
alert("incorrect");
incorrect++;
}
if(question2 == "jelly")
{
alert("correct!");
correct++;
}
else{
alert("incorrect");
incorrect++;
}
if(question3 == "bread"||"jelly"||"peanut butter"){
alert("correct!");
correct++
}
else{
alert("incorrect");
incorrect;
}
alert(correct);
}
最佳答案
首先,您似乎熟悉其他编程语言。例如 C# 或 java,但您不了解 DOM 操作的基础知识。所以现在请耐心等待,直到我向您详细解释。
首先,DOM 是(文档对象模型),它基本上是使用标记语言 (HTML) 创建的图像。基本上这是在浏览器上显示并由 javascript 操作的内容。就像本页上的按钮或我现在正在输入的文本框或上面的导航栏。
因此,快速回顾一下 DOM 是使用 HTML 创建并使用 javascript 操作的。
由于 DOM 是由 html 创建的,因此在加载 html 之前您将无法操作它。在 html 页面顶部添加 script 标记意味着您运行不存在的操作。因此,您必须在 html 页面末尾添加 script 标签,位于正文结束标签之前。
<script src = "scripts/main.js"></script>
</body>
现在,当您想要操作一个元素时,您必须将其存储在变量中,而执行此操作的方法是使用选择器。
您有三个选项,但为了节省时间,我不会列出这 3 个选项,而是列出最好且最常用的一个。你可以用谷歌搜索其他的,但我认为这不值得。
因此,如果您了解 css,您可以通过名称、id 或类来选择组件。javascript 中有一个叫做查询选择器的东西,它的用法如下。
var x = document.queryselector('css-selector');
您添加一个 css 选择器来代替 css-selector 部分。例如,如果元素具有“英雄”类别。您将用 .hero 替换 css-selector,或者如果它的 id 为“hero”,您将用 #id 替换 css-selector。
那么你应该使用变量名来操作元素。
这里有更多有用的链接,您可以查看。 JavaScript
关于javascript - 在 html/javascript 警报中进行测验不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49479026/
我知道这曾经是一个话题,但搜索后我找不到答案 - 也许我的问题太基本了。不过,我正在创建一个 html 测验 - 5 页,分数从一页到下一页,然后在最后评分。 这是我正在尝试使用的代码,但它根本不起作
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我正在做一个简单的 php 问答游戏。我将问题和答案存储在数据库中。我的 tblQuiz 的表结构是这样的: _id, question, answer1, answer2, answer3, cor
我在考试中遇到了这个问题。 以下不正确 javascript 代码的输出是什么?错误是什么? num=0; if (num > 10); { num = num + 10; } alert(n
我在 JavaScript 中验证 4 个问题多项选择测验时似乎遇到了一些问题。现在,如果没有选择任何答案,则会弹出警报,但即使只选择了一个答案,警报也不会弹出。我正在将我的函数作为提交按钮的 onc
我正在尝试使用 JavaScript 构建一个问答游戏。 测验答案存储在变量中,如下所示: var correctAnswer = $('#createCorrectAnswer').val(); 然
下面我做了一个小测验,有 4 个问题,问题 2,3 和 4 被 CSS 隐藏了,但是你可以尝试从 CSS 中删除样式 (".pytja2, .pytja3, .pytja4 { display: no
private void startGame() { System.out.println("Exercises must be completed as quickly as pos
这听起来像是我之前问过的问题,但它只得到了部分回答。所以我想从我提出的问题开始。然后,一旦到达最后一个问题(#5),它就会返回到第一个问题(#1),当到达起始问题时,它将停止。我尝试在以下代码中执行此
愚蠢的问题,但我的教授不回复电子邮件,所以我在这里问。我现在正在复习期末考试,并且正在复习期中考试来学习。现在,这真的很愚蠢,因为我两个月前就答对了这个问题。但对于我的一生来说,现在回想起来,我无法弄
我无法编写一个循环来计算我为我的 wordpress 网站创建的测验的分数。 测验样式是“将 A 列中的项目与 B 列中的项目进行匹配”。 B 列项目使用选择元素来匹配 A 列中的相应项目。 我能想到
为什么选择不正确单选选项时,if语句中的else仍然出现? else 部分只应在未选择单选按钮时出现。真正的结果是下一个问题和可能的答案出现。这是 jsfiddle .我做错了什么? function
我正在尝试为西类牙语类(class)创建测验。我对 JavaScript 经验不多,但对 html 和 CSS 相当精通。我有一个问题,然后是三个带答案的单选按钮。有两个错误答案和一个正确答案。我总共
我正在编写一个允许用户设置个人测验的程序(如记事卡式系统)。参加测验时,用户会在每个问题上计时。虽然答案不会是多项选择,但它们将由用户输入。 有没有一种方法可以让我充分接受那些不是他们第一次设置测验时
我正在尝试根据找到的教程创建一个简单的测验。 http://css-tricks.com/building-a-simple-quiz/ 不幸的是,这让我无法自拔,答案可能非常简单。 我让这个工作完美
最近我遇到了以下测验。想象一下我们有这张 table +--------+ | colors | +--------+ | red | | black | | white | | green
这里的 W3Schools 网站上发布了一个 jQuery 测验... http://www.w3schools.com/quiztest/quiztest.asp?qtest=jQuery 问题#1
我正在写一个简单的在线测验。有四个单选按钮作为选择。最初,脚本仅填充第一个问题的选项。之后,用户应该选择下一个并单击按钮。如果答案与正确的匹配,则总数递增。否则,将加载下一个问题。提交第 10 个问题
我不是 Haskell 程序员,但我对以下问题感到好奇。 非正式函数规范: 令 MapProduct 为一个函数,它采用名为 F 的函数和多个列表。它返回一个列表,其中包含使用每个可能组合中每个列表中
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
我是一名优秀的程序员,十分优秀!