简体   繁体   English

使用Jetbrains Webstorm更改HTML5和Javascript中图像的src

[英]Changing the src of an Image in HTML5 and Javascript using Jetbrains Webstorm

so I've been trying to make X and Os for a HTML5/JS course project thinking it would be easy, but have had several days of trouble trying to change an image's source from "Tile.png" to "XX.png". 因此,我一直试图让HTML5 / JS课程项目的X和Os变得容易,但是尝试将图像源从“ Tile.png”更改为“ XX.png”却遇到了几天的麻烦。 I have found similar threads on the site on very similar problems, but none of them worked for me, they all got the 'rare' error though, so I'm thinking there's a double whammy going on here. 我在网站上发现了类似的线程,但都遇到了非常类似的问题,但是它们都不为我工作,尽管它们都遇到了“罕见”错误,所以我认为这里发生了双重打击。 Help pls! 请帮助!

Here are the two errors I've seen during the hundreds of attempts using javascript and HTML5 for various attempts. 这是我在使用javascript和HTML5进行各种尝试的数百次尝试中看到的两个错误。

Uncaught ReferenceError: $ is not defined client.js:102
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

or

attempt to set image src to null (This showed up in most attempts, the other error is a rare occurrence that shows up when I think I've nailed it.)

- The code consists of a HTML5 file and a Javascript file which just holds variables that aren't used yet. -该代码由一个HTML5文件和一个Javascript文件组成,这些文件仅包含尚未使用的变量。 Here is the problem code showing the javascript function and the HTML button and clicking that runs it. 这是显示javascript函数和HTML按钮并运行它的问题代码。 The error pops up when the button is clicked, so I believe the code is in the javascript part. 单击按钮时会弹出错误消息,因此我认为代码在javascript部分中。

<script>
  function YUNOCHANGE()
  {
    var img = document.getElementById("tst1");
    img.src = "Images/XT.png";
  }
</script>

<button onclick="YUNOCHANGE();" type="button" id="tst1" name="One" alt="Grey tile" height="175" width="200" style="text-align:center">
  <img src="Tile.png"/>
</button>

The Button has no property "src": 该按钮没有属性“ src”:

<script>
  function YUNOCHANGE()
  {
    var img = document.getElementById("img1");
    img.src = "Images/XT.png";
  }
</script>

<button onclick="YUNOCHANGE();" type="button" id="tst1" name="One" alt="Grey tile" height="175" width="200" style="text-align:center">
  <img id="img1" src="Tile.png"/>
</button>

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

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