实例如下:
<script>
var imgs =["https://cache.tdyun.com/upload/information/20200622/114/59400.jpg",
"https://cache.tdyun.com/upload/information/20200622/114/59402.png",
"https://cache.tdyun.com/upload/information/20200622/114/59403.jpg",
"https://cache.tdyun.com/upload/information/20200622/114/59404.jpg",
"https://cache.tdyun.com/upload/information/20200622/114/59405.jpg",
"https://cache.tdyun.com/upload/information/20200622/114/59406.jpg",
"https://cache.tdyun.com/upload/information/20200622/114/59407.jpg",
"https://cache.tdyun.com/upload/information/20200622/114/59408.jpg",
];
var index=Math.floor(Math.random()*8);
var img = imgs[index];
function time(){
document.body.style.backgroundImage="url("+img+")";
}
document.body.onload = function(){
time();
}
</script>
以上这篇js设置随机切换背景图片的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持天达云。