簡體   English   中英

在頁面加載時更改div內容

[英]Changing div content on page load

我正在尋找一種解決方案,其中div內容隨頁面加載隨機變化。 很像頁面加載時的JavaScript圖像。 我在下面的代碼中做了進一步的說明。

我可以在頁面加載時使用JavaScript對內容進行隨機化處理,例如圖像,但是這里是divs,我不確定如何更改其中的內容。

<div class="row BSlots">
    <div class="Grid_4 fl">
        /* This would be the code which would change */
        /* For example once it would be <div class="hello"><p>Hi</p></div> and the other <iframe="Link"/> */
    </div>
    <div class="Grid_4 fr">
        <script>Widget2(); /* Don't mind this, loading an actual JS image randomizer here */</script>
    </div>
</div>

不使用JS就可以實現嗎? 如果沒有,我將不勝感激一個基本的例子:)

是的,沒有Java語言就可以實現。 這取決於您使用哪種服務器端技術。 您可以創建一個模板並插入服務器端勒索圖像標簽。 也可以通過javascript來實現。 如果要使用jQuery,可以執行以下操作:

$(function(){
  $(".Grid_4 fl").html(generateRandomImageHtml());
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM