<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="div" style="width:100px;height:100px;background-Image:url(b.jpg)"></div>
</body>
<script>
var mydiv = document.getElementById('div');
var imgArray = ['a.jpg', 'b.jpg']
var i = -1;
setInterval(function () {
i++;
i %= imgArray.length;
mydiv.style.backgroundImage = 'url(' + imgArray[i] + ')';
}, 5000);
</script>
</html>
温馨提示:答案为网友推荐,仅供参考