简体   繁体   English

正确答案后,脚本中的图片无法正常工作

[英]image in script wont work after correct answer

I currently have a script which, if the answer is correct, spits out an image. 我目前有一个脚本,如果答案是正确的,它会弹出一个图像。 If it is a good answer it will give out a green checkmark, and if it is wrong it will give out a red cross. 如果答案是正确的,则会发出绿色的对勾,如果错误,则会发出红色的叉。
However it doesn't spit out the image, any ideas? 但是它不会吐出图像,有什么想法吗?

I have the idea that the "image="src= ../../../image/goed.png" is wrong and should be replaced, I have no idea what would be the right code. 我的想法是“ image =” src = ../../../image/goed.png“是错误的,应该替换,我不知道什么是正确的代码。

function schrijvenles1(){
var text = document.getElementById("schrijven-les1").value;
var:text;

//het antwoord is correct
if(text="Ik heet Marie." || "ik heet Marie." || "ik heet marie" || "Ik heet marie") {
    image =" src=../../../image/goed.png";
}
// het antwoord is iets anders
else {
    image = src="src=../../../image/fout.png";
    document.getElementById("goed-fout") = image;

} }

this is the html code 这是HTML代码

        <p id ="goed-fout"> </p>
    <!-- geluidsfragment schrijfopdracht 1-->

    <button id="voortgang-button" onclick="playMusic1()" value="button">    
        <img id="afspeelbutton"   src ="../../../image/afspeelbutton1.png"> 

        <audio
            id="geluidsopname1" src="../../../voice-recording/marie.mp3">
        </audio>

        <input id="schrijven-les1" type="text" >  </input> 
    </button>
    <button 
        id="controle-luisteren" onclick="schrijvenles1()">Check
    </button>[enter image description here][1]

there is an image addeed to the page, which will give you a better idea of how the page looks and maybe give some better insights. 页面上有一张图片,可以使您更好地了解页面的外观,并可能提供一些更好的见解。

when checking if the answer is correct, change this: 检查答案是否正确时,请更改此内容:

if(text="Ik heet Marie." || "ik heet Marie." || "ik heet marie" || "Ik heet marie")

to this: 对此:

if (text=="Ik heet Marie." || text == "ik heet Marie." || text == "ik heet marie" || text == "Ik heet marie")

Also, I did not understand you selecting a "p" element and setting a string to it. 另外,我不理解您选择“ p”元素并为其设置字符串。 You should select a image element and change it's src property like this: 您应该选择一个图像元素并按如下所示更改其src属性:

document.getElementById("imageid").src="../../../image/afspeelbutton1.png";

When you are sure your code is right and you suspect only of the image relative path, a good tip is to inspect your requests on the Network tab of your browser's development tools. 当您确定代码正确无误并且仅怀疑图像相对路径时,一个很好的技巧是在浏览器开发工具的“网络”选项卡上检查您的请求。 So you will see the resulting absolute path your browser is requesting and so you can correct it. 因此,您将看到浏览器正在请求的结果绝对路径,因此可以对其进行更正。

Here is a working example: https://jsfiddle.net/5w80jfd0/ 这是一个工作示例: https : //jsfiddle.net/5w80jfd0/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM