【发布时间】:2016-07-12 11:46:17
【问题描述】:
我正在寻找的是可以添加到我的代码中的东西,它会改变我的动画并让一系列光在没有用户输入的情况下自动亮起..
到目前为止,这是我的代码,我需要将其从按钮单击功能更改为自动灯光序列的代码。
<h1>Changing HTML images</h1>
<p> Click the button to change the Traffic Lights </p>
<img id="myImage" onclick="changeimage()" src="red.jpg" width="100" height="180">
<button type ="button"
onclick="changeimage()">Change the traffic light</button>
<script>
var counter = 0
var image = ["red.jpg","redandorange.jpg","orange.jpg","green.jpg"]
function changeimage () {
window.alert(counter)
counter++
if(counter > 3 ){
counter = 0
}
document.getElementById('myImage').src=image[counter]
}
</script>
<body>
</body>
</html>
【问题讨论】:
-
这很简单 -
setInterval( changeimage, 1000 ); -
就在你的函数结束之后。
标签: javascript input task sequence light