this is my first question on StackOverflow, so I am sorry if this is not up to standard.
<html>
<body>
<button onclick="ChangeLights()">Change Lights</button>
<img src="redlight.jpg" id="traffic" width="83" height="232">
<script>
var imgarray = ["redlight.jpg", "yellowlight.jpg", "greenlight.jpg"];
document.getElementById("traffic").innerHTML = traffic;
function ChangeLights(){
document.getElementById("traffic").src = "redlight.jpg";
}
function ChangeLights() {
if (traffic.src.match(imgarray[0])){
traffic.src = imgarray[1];
}else if (traffic.src.match(imgarray[1])){
traffic.src = imgarray[2];
}else if (traffic.src.match(imgarray[2])){
traffic.src = imgarray[3];
}}
</script>
</body>
</html>
Whenever I press the button, the image does not appear.
Aucun commentaire:
Enregistrer un commentaire