Javascript 不从文本编辑器执行

标签 javascript html css

我已经尝试搜索此问题的解决方案,但仍未找到。 HTML 执行正常,但 Javascript 未执行。我已将其包含在 index.html 文件中并尝试使用外部 .js 文件。仍然无法让我的 javascript 执行。还有 CSS 不执行的问题。需要一些新的眼睛。谢谢...

<!doctype html>
<html>
<head>
<title> X-Ray Quiz </title>
<link href = “style.css” rel = “stylesheet”>
<link href = “https://fonts.googleapis.com/css?family=Lato” rel=    
“stylesheet”>


</head>

<body>
<h5><font color=orange > Quick Asessment </h5></font>

<form id = "quiz" name = "quiz">

<p> Identify this image </p>
<img src=name.jpg height=30% width=30%><br>
<input id= "textbox" type= "text" name= "question1">

<p> identify this image <p>
<img src= name.jpg height=30% width=30%><br>
<input type= "radio" type= "mc" name= "question2" value= "normal">  
normal <br>
<input type= "radio" type= "mc" name= "question2" value= “Choice”>   
COPD<br>

<input type= "radio" type= "mc" name= "question2" value= “Choice”>    
Choice<br>

<p> Identify this image <p>
<img src= name.jpg height=30% width = 30%><br>
<input type= "radio" type= "mc" name= "question3" value= “Normal”> 
Normal <br>

<input type= "radio" type= "mc" name= "question3" value=   
“choice”>choice<br>

<input type= "radio" type= "mc" name= "question3" value=   
“Asthma”>Asthma<br>


<input id= "button" type= "button" value= "Submit" onClick= 
"function();">


</form>
<div id = “after_submit”>
<p id = “number_correct”></p>

主要.js

function  check () {
var question1 = document.quiz.question1.value;
var question2 = document.quiz.question2.value;
var question3 = document.quiz.question3.value;
var correct = 0;

If (question1 == “normal”) {
correct ++;
}
if (question2 == “COPD”) {
correct ++;
}
if (question3 == “Fibrosis”) {
correct ++;
}

document.getElementById(“after_submit”).style.visibility = “visible”;
document.getElementById(“number_correct”).innerHTML = “You got “ +    
correct + “correct.”;

}

var messages = [ “Great job”, “That’s just okay”, “ You really need to   
do better!”];

var range;

if (correct <1) {
range =2;

if (correct > 0 && correct<3) {
range = 1;
}

if (correct>2) {
range = 0;
}

document.getElementById(“after_submit”).style.visibility = “visible”;
document.getElementById(“message”).innerHTML = messages[range];
document.getElementById(“number_correct”).innerHTML = “ You got “ +   
correct + “ correct. “;


 } 

最佳答案

首先,您的 JavaScript 文件没有链接到您的 HTML。您可能需要添加:

<script src="main.js"><script>

(或者你的HTML被 chop 了,到最后了?)

在您的 HTML 中,您没有调用正确的 JavaScript 函数:

<input id= "button" type= "button" value= "Submit" onClick="function();">

现在,您的 JavaScript 读取

function check () { ... }

所以应该是onClick="check();"因为那是您的函数的名称。

关于Javascript 不从文本编辑器执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49331742/

相关文章:

jquery - 多图只获取第一个div的高度

css - 两个行内 block 元素总是在同一行

css - 为什么无样式的输入文本的边框宽度为 2px?

javascript - 创建单个对象

javascript - 平板电脑的工具提示或弹出窗口?

javascript - 在javascript中获取鼠标在图像上的点击位置?

html - CSS - 计算不准确

javascript - 拉取标题并以列表格式显示在div中

JQuery 输入动态检查

显示空白的 Jquery 内容选项卡