我不确定我将如何添加按钮,请帮助我需要它来停止并启动幻灯片放置,谢谢我已经无法让它工作大约两个小时我刚刚开始编码,这是唯一的我坚持不懈,再次感谢。
<html>
<head>
<script type="text/javascript">
var slideimages = new Array()
slideimages[0] = new Image()
slideimages[0].src = "https://www.missionmanager.com/wp-content/uploads/2015/08/number-1-199440.jpg"
slideimages[1] = new Image()
slideimages[1].src = "https://www.missionmanager.com/wp-content/uploads/2015/08/red-number-2.jpg"
slideimages[2] = new Image()
slideimages[2].src = "https://www.missionmanager.com/wp-content/uploads/2015/08/red-number-3.jpg"
</script>
</head>
<body>
<img src="" id="slide" width="150" height="260" />
<script type="text/javascript">
var step=0
function slideit(){
document.getElementById('slide').src = slideimages[step].src
if (step<2)
step++
else
step=0
setTimeout("slideit()",2500)
}
slideit()
</script>
</body>
</html>
答案 0 :(得分:0)
你走了:
我的更改摘要
<html>
<head>
<script type="text/javascript">
var slideimages = new Array()
slideimages[0] = new Image()
slideimages[0].src = "https://www.missionmanager.com/wp-content/uploads/2015/08/number-1-199440.jpg"
slideimages[1] = new Image()
slideimages[1].src = "https://www.missionmanager.com/wp-content/uploads/2015/08/red-number-2.jpg"
slideimages[2] = new Image()
slideimages[2].src = "https://www.missionmanager.com/wp-content/uploads/2015/08/red-number-3.jpg"
</script>
</head>
<body>
<img src="" id="slide" width="150" height="260" />
<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>
<script type="text/javascript">
var step = 0;
var myTimer = null;
function slideit() {
document.getElementById('slide').src = slideimages[step].src
if (step < 2)
step++
else
step = 0
myTimer = setTimeout("slideit()", 2500)
}
function start() {
slideit();
}
function stop() {
if (myTimer != null)
clearTimeout(myTimer);
}
</script>
</body>
</html>