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