在页面加载
之后,我编写了这个小JavaScript来更改div的背景图像<div id="header">
<script language="JavaScript">
<!--
var playlist = new Array();
playlist[0]="background: url('image1') no-repeat center center; background-size: cover;";
playlist[1]="background: url('image2') no-repeat center center; background-size: cover;";
playlist[2]="background: url('image3') no-repeat center center; background-size: cover;";
var c = Math.floor(Math.random()*playlist.length);
document.getElementById('header').style = playlist[c];
-->
</script>
<p>This is some text</p>
<p>This is some text</p>
<p>This is some text</p>
</div>
它工作正常,但似乎与Internet Explorer / edge不兼容。哪里我做错了?
答案 0 :(得分:0)
.style在IE中有效吗?您是否尝试过.setAttribute(&#39; style&#39;,播放列表[c])?