<script language="JavaScript" type="text/javascript">//随机图片代码tips = new Array(3);tips[0] = '<img src="tiggo32.png" border="0" />';tips[1] = '<img src="tiggo31.png" border="0" />';tips[2] = '<img src="tiggo33.png" border="0" />';index = Math.floor(Math.random() * tips.length);document.write(tips[index]);</script>怎么给这段代码加一个时间! 到了自动切换下一个随机图片
1 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"> <title>Document</title>
</head>
<body>
<img id='img' src="" alt=""> <script> window.onload = function () { var imgDom = document.getElementById('img') var imgArr = ['tiggo32.png','tiggo32.png','tiggo32.png'] function setImg (){ var index = Math.floor(Math.random() * tips.length) imgDom.src = imgArr[index] } setImg() setInterval( function (){ setImg() }, 5000) } </script>
</body>
</html>
添加回答
举报
0/150
提交
取消