js实现刷新页面出现随机背景图
直接上代码:
<script>
var bodyBgs = [];
bodyBgs[0] = "IMG/01.jpg";
bodyBgs[1] = "IMG/02.jpg";
bodyBgs[2] = "IMG/03.jpg";
bodyBgs[3] = "IMG/04.jpg";
bodyBgs[4] = "IMG/05.jpg";
var randomBgIndex = Math.round( Math.random() * 4 );
//输出随机的背景图
document.write('<style>body{background:url(' + bodyBgs[randomBgIndex] + ')top center no-repeat; background-size:cover;}</style>');
</script>