gpt4 book ai didi

Javascript 不从文本编辑器执行

转载 作者:太空宇宙 更新时间:2023-11-04 07:31:45 26 4
gpt4 key购买 nike

我已经尝试搜索此问题的解决方案,但仍未找到。 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com