在每个页面加载时显示随机 DIV(对于花哨的框模式)


Show Random DIV on every page load (For fancybox modal)

当访问者离开网站时,我显示了一个花哨的模态窗口。它工作正常。但作为拆分测试,我想在随后的访问中向访问者展示来自 2 个不同div 的随机内容。

意义:

1

)当访问者1来并试图离开网站时,他可能会看到带有内容1或2的花式框

2

)当访问者2来并试图离开网站时,他可能会再次看到带有内容1或2的花式框

等等...

花式框模态的实际代码是:

<div id="inline" class="various2" style="display:none;">
      <div style="padding:20px;">
             This is the content of that shows inside the fancybox modal.
       </div>
</div>

现在对于内部div,我想放置另一个具有一些不同内容的div,其中一个应该在每次页面加载时随机显示,而另一个是 display:none...

我试过这个:每次页面刷新如何显示许多div中的一个?但它不起作用并显示两个div 都可见......

谁能帮忙?

编辑:回答了原始问题。现在,如何在每次页面加载时显示备用div。不是随机的。像访客 1,2,3,4 这样的东西分别看到div 1、2、3、4。

我知道这需要一些服务器端代码,任何人都可以帮助一些基本的 php 代码吗?

出于某种原因,我更喜欢时间戳而不是随机

.HTML

<div id-="fancy_box">
    <div id="inline" class="various1" style="display:none;">
        <div style="padding:20px;">
             This is the content of that shows inside the fancybox modal 1.
       </div>
    </div>
    <div id="inline" class="various2" style="display:none;">
        <div style="padding:20px;">
             This is the content of that shows inside the fancybox modal 2.
       </div>
    </div>
</div>

杰奎里

$(function(){
    $(".various"+(new Date().getTime() % 2 +1)).css("display", "block");
});

哦,小提琴在这里

检查这个小提琴。我已经删除了显示:您的div 上没有内联 id,以便查看结果

http://jsfiddle.net/bPK8y/

var value1 = 'my_first_div';
var value2 = 'my_second_div';
var chosenValue = Math.random() < 0.5 ? value1 : value2;
var chosenDiv = document.getElementById(chosenValue);
chosenDiv.style.display = "block";

.HTML

<div id="inline" class="various2">
  <div style="padding:20px; display: none;" id="my_first_div">
      This is the content of that shows inside the fancybox modal. CONTENT 1
  </div>
  <div style="padding:20px; display: none;" id="my_second_div">
      This is the content of that shows inside the fancybox modal. CONTENT 2
  </div>
</div>