直接上代码:
<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>
时间: 2024-10-09 20:48:09