简体   繁体   English

在页面加载时更改div内容

[英]Changing div content on page load

I'm looking for a solution, in which div content changes on page load, randomly. 我正在寻找一种解决方案,其中div内容随页面加载随机变化。 Much like a JavaScript image on page load. 很像页面加载时的JavaScript图像。 I have made further notes in the code below. 我在下面的代码中做了进一步的说明。

I could do a randomize the content like images with JavaScript on page load, but here it's divs and I'm not sure how to change content inside them. 我可以在页面加载时使用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>

Can this be achieved without using JS? 不使用JS就可以实现吗? If not, I'd appreciate a basic example which I could fiddle with :) 如果没有,我将不胜感激一个基本的例子:)

Yes it could be achieved without Javascript. 是的,没有Java语言就可以实现。 It depends on which serverside-technology you use. 这取决于您使用哪种服务器端技术。 You could create a template and insert serverside ransom image-tags. 您可以创建一个模板并插入服务器端勒索图像标签。 It is possible too, to do it via javascript. 也可以通过javascript来实现。 If you want to use jQuery, you could do something like: 如果要使用jQuery,可以执行以下操作:

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

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

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