尝试在每次加载页面时从数组中随机生成一个div.
我已经设法将来自几个随机图像生成器的位组合在一起以创建下面的内容.
当数组中的[0]包含图像时,就像其他图像一样,一切都按预期工作.一旦我用div或视频替换[0]的图像,一切都没有显示,页面是空白的.
我出错的任何建议?
<link rel="stylesheet" type="text/css" href="style.css" >
<script type="text/javascript">
function random()
{
video = new Array(4);
video[0] = "<div class="clip"> </div> ";
video[1] = "<a href=''><img src='http://lorempixel.com/output/city-q-c-640-480-3.jpg' alt='' /></a>";
video[2] = "<a href=''><img src='http://lorempixel.com/output/fashion-q-c-640-480-6.jpg' alt='' />";
video[3] = "<a href=''><img src='http://lorempixel.com/output/technics-q-c-640-480-1.jpg' alt='' />";
for(var i = 0; i < video.length; i++)
{
index = Math.floor(Math.random() * video.length);
document.write(video[index]);
}
}
</script>
</head>
<body>
<script type="text/javascript">
random();
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
你需要逃避你的报价.尝试:
video[0] = "<div class=\"clip\"> </div>";
或使用单打:
video[0] = "<div class='clip'> </div>";
另外,你知道你的div是空的,对吗?除非你的风格能够使它显示某些东西,否则它将显示为空白.
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |