繁体   English   中英

使用数组时Div不会显示

[英]Div will not display when using an array

尝试在每次页面加载时从数组随机生成一个div。

我设法将一些随机图像生成器中的位组合在一起以创建以下内容。

当数组中的[0]包含图像时,就像其余图像一样,一切都会正常进行。 将[0]的图像替换为div或视频后,什么都没有显示,并且页面空白。

有什么建议我要去哪里吗?

 <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>

您需要转义报价。 尝试:

video[0] = "<div class=\\"clip\\"> </div>";

或使用单打:

video[0] = "<div class='clip'> </div>";

另外,您知道自己的div是空的,对吗? 除非您的样式能够使其显示某些内容,否则它将显示为空白。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM