繁体   English   中英

在每次加载页面时显示随机DIV(适用于fancybox模式)

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

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

含义:

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

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

等等...

fancybox模态的实际代码是:

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

jQuery查询

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

暂无
暂无

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

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