我的代码似乎在 Firefox 上运行完美。但是当我想在 IE 或 Chrome 上运行它时,我的背景似乎是空白的。我的代码有问题吗?还是我测试过的浏览器根本不支持它?
<html>
<head>
<script>
window.onload = function () {
var imgs = [
'images/1.jpg',
'images/2.jpg',
'images/3.jpg',
'images/4.jpg',
'images/5.jpg',
'images/6.jpg'
];
document.body.style = 'background: url(' + imgs[Math.round(Math.random() * imgs.length)] + ') no-repeat ; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;';
}
</script>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<?php include ("header.php"); ?>
<div align="center" >
<?php include ("main.php"); ?>
<?php include ("footer.php"); ?>
</div>
</body>