简体   繁体   English

在灯箱(colorbox)中打开随机页面

[英]Open random page in lightbox (colorbox)

How can I make a link open a random page from a list of pages in a colorbox lightbox based on the following code: 如何根据以下代码使链接从Colorbox灯箱的页面列表中打开随机页面:

<a class="colorbox" href="page1.html"...

==========UPDATE========== ==========更新==========

Thanks Tomm... 谢谢汤姆...

I edited your code as follows: 我对您的代码进行了如下编辑:

$(document).ready(function() {
    $("a.random").click(function() {
       var randomnumber = Math.floor(Math.random()*8+1);
       if (randomnumber == '1'){
           $(this).attr("href","anypageiwant.html");
       }
       else if....

However, sometimes the same random number/page is chosen more than once. 但是,有时相同的随机数/页会被多次选择。 Is there any way to avoid this? 有什么办法可以避免这种情况?

$(document).ready(function() {
    $("a.colorbox").click(function() {
        $(this).attr("href","print"+Math.floor(Math.random()*11)+".html");
    });
});

Just replace the 11 with whatever number of pages you've got plus 1 (ie if you have page1.html to page15.html use Math.random()*16). 只需将11替换为您拥有的任意数量的页面加1(即,如果您的page1.html至page15.html使用Math.random()* 16)。

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

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