我的图片赢得了't显示
My images won't show
当我试图加载此页面时,我的图像不会显示!我正在尝试制作一个红绿灯序列(英国),当按下变灯按钮时,它会显示所有颜色!
<!DOCTYPE html>
<html>
<body>
<h1><u><b>Changing Traffic Lights</b></u><h1>
<button type="button" onClick="changeLights()"> Change Lights </button> <!-- Creates a button to change the lights with -->
<img id ="trafficlight" src="red.jpg"></img> <!-- Creates the first visible image on the page and gives it an ID so it can be called up later -->
<script>
var trafficlights = ["red-amber.jpg","green.jpg","amber.jpg","red.jpg"] //creates an array for the lights
var currentlight = 0 //Creates a counter variable
function changeLights () { //Calls up a function and designs it
document.getElementById("trafficlight").src=trafficlights[currentlight] //Calls up the image and enables it to be changed
currentlight=currentlight+1 //Adds one to the counter
if (currentlight>3){
currentlight=0
}
}
</script>
</body>
</html>
您的代码可以正常工作。但是您的图像源路径一定有问题。因为当我将图像更改为像lorempixel这样的远程图像时,这是正确的。
在这里工作。
尝试修复JS中的图像路径。祝你好运
var trafficlights = ["http://lorempixel.com/100/100","http://lorempixel.com/100/90","http://lorempixel.com/100/100","http://lorempixel.com/100/110"]
相关文章:
- 我希望只有在我滚动页面后才能显示我的返回页首图标
- 希望在单击href链接时显示我的广告
- 我想隐藏/显示我的SVG元素,同时在anguarJS中使用它
- 为什么我的html弹出窗口显示我的函数的文本,而不是运行它们
- 我怎样才能显示我的子数组解唱 Angular js
- 在谷歌地图上显示我的位置
- 如何在谷歌地图上显示我的数据库地址,不带lat和long
- 为什么浏览器不't显示我的日历
- ng-repeat / ng-bind 不会显示我的数据
- 我无法使用 d3.js 在每月数据中显示我的 x 轴
- 为什么我的 onclick 事件不显示我的 JSON 文件
- Firebug 不显示我的 JavaScript?找不到错误
- 我只想在警报中打印数据,但每当它提醒我 [对象对象] 但我希望它会显示我的表数据行
- var.push 并在 HTML 页面中显示我的新临时信息
- 为什么IE无法正确显示我的HttpHandler Web应用程序中的特殊符号
- 谷歌地图没有显示我的位置
- 如何使用 Jquery 在段落中以纯文本形式显示我的数据,该段落以 JSON 文本包装
- JavaScript代码很好,但网页预览只显示我的html工作
- 谷歌地图API v3:我在热图上显示我的数据时遇到问题
- 摘要循环显示我的数组没有变化(视图不会刷新)