我的交通灯代码不能工作了。它说,第30行有语法问题,我不知道如何修复它。我也需要做相同的代码,但当我按下“改变灯”按钮,每次我按它,一个不同的彩色图像,从交通灯应该出现。然而,当我试图通过按下按钮来改变交通灯时,红灯仍然亮着,不会变成琥珀色。
<!DOCTYPE html>
<html>
<body>
<h1>Traffic Light</h1>
<button type="button" onclick="changeLights"()>Change Lights </button>
<script>
var traffic_light = new Array (3)
function lights(){
traffic_light = new Image(300,150)
traffic_light.src = "traffic_light_red.jpg";
traffic_light = new Image(300,150)
traffic_light.src = "traffic_light_redAmb.jpg";
traffic_light = new Image(300,150)
traffic_light.src = "traffic_light_green.jpg";
traffic_light = new Image (300,150)
traffic_light.src = "traffic_light_amber.jpg";
}
function change() {
traffic_lights++
var traffic_lights = 0
number == number +1
}
document.traffic_light_images.src = traffic_light[traffic_lights].src
}
</script>
<img src = "traffic_light_red.jpg" name "traffic_light_images" height = "300" width = "150">
</body>
</html>发布于 2017-01-24 11:54:13
我看到了一些事情(我没有尝试执行您的代码):
例:
var traffic_light = new Array (3)这是一个比较,你可能想增加,但我不知道你的目的
https://stackoverflow.com/questions/41827457
复制相似问题