<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Task 3- Traffic Light Sequence </h1>
<img id="light" src="./assets/red.png" height="205" width="95">
<button type="button" onclick="changeLights()">Change Lights</button>
<script>
var colours = ["./assets/red.png","./assets/red_and_amber.png", "./assets/green.png","./assets/amber.png" ];
var index = 0;
function changeLights() {
index = index + 1;
if (index == colours.length)
index = 0;
var image = document.getElementById('light');
image.src = colours[index];
}
</script>
</body>
</html>
這個代碼是顯示一個紅綠燈序列的目的。先是紅色,然後是紅色和琥珀色,然後是綠色,然後回到琥珀色,然後回到紅色。我不確定這個功能是一行一行地完成的。是否有人可以解釋的功能林不知道的使用指數
非常感謝。 – User123