所以我一直在尝试为HTML5/JS课程项目制作X和O,认为这很容易,但尝试更改时遇到了几天的麻烦将图像的来源从“Tile.png”更改为“XX.png”。我在网站上发现了类似的问题,但它们都没有为我工作,但他们都得到了“罕见”的错误,所以我认为这里会有双重打击。请帮助!使用Jetbrains更改HTML5和Javascript中的图像的src Webstorm
以下是我在使用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.)
- 代码由一个HTML5文件和刚刚认为尚未使用的变量的JavaScript文件中。这里是显示javascript函数和HTML按钮并单击它运行它的问题代码。当按钮被点击时弹出错误,所以我相信代码是在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>
对于初学者来说,如果引用'#tst1'(又名'button')当你应在'src'变化引用'img'元素。给“img”一个ID并使用它,然后报告结果。 – Deryck
OMFG它很努力,非常感谢!我在这个问题上花了好几天时间,看起来我受到了汽车的撞击!非常感谢IGKDWKGDWHSGK谢谢;'D – Friaza
大声笑我猜应该把它放在答案。很高兴你的问题现在得到解决。 – Deryck