JavaScript代码:交通灯
我不能用我的交通灯代码工作。它说第30行有语法问题,我不知道如何修复它。我还需要制作相同的代码,但每次按下“更改灯”按钮时,都会出现与交通灯不同的彩色图像。但是,当我试图通过按下按钮来改变灯时,交通灯保持红色,不会变为琥珀色JavaScript代码:交通灯,javascript,Javascript,我不能用我的交通灯代码工作。它说第30行有语法问题,我不知道如何修复它。我还需要制作相同的代码,但每次按下“更改灯”按钮时,都会出现与交通灯不同的彩色图像。但是,当我试图通过按下按钮来改变灯时,交通灯保持红色,不会变为琥珀色 <!DOCTYPE html> <html> <body> <h1>Traffic Light</h1> <button type="button" onclick="changeLights"()>
<!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>
我看到一些我没有尝试执行您的代码的东西: 前许多缺失逗号: 例如:
var traffic_light = new Array (3)
然后不是语法错误,而是这一行:
number==number+1//且缺少逗号
这是一个比较,你可能想增加,但我不知道你的目的
示例中未定义函数changeLights。
你有一个额外的结束大括号}问题看起来和这个差不多