我一直在尝试创建一个JavaScript交通灯序列作为实验。代码似乎是正确的但由于某种原因,它不起作用。有人可以帮忙吗?
<!DOCTYPE html>
<html>
<body>
<h1>Traffic Lights Task 3 JavaScript Controlled Assesment 2017</h1>
<img id="Traffic_Lights" src="RED.png">
<button type="button" onclick="changeLights()">Change Lights</button>
<script>
var image = ["RED.png","AMBERRED.png","GREEN.png","AMBER.png"];
var Traffic_Light_Sequence = document.getElementById('Traffic_Lights');
function changeLights() {
if (Traffic_Lights.src == "RED.png") {
Traffic_Lights.src = image[1];
} else if (Traffic_Lights.src == "AMBERRED.png") {
Traffic_Lights.src = image[2];
} else if (Traffic_Lights.src == "GREEN.png") {
Traffic_Lights.src = image[3];
} else {
Traffic_Lights.src = image[0]
}
}
</script>
</body>