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

发布于 2024-11-27 15:04:44 字数 498 浏览 4 评论 0原文

如何根据以下代码使链接从 colorbox 灯箱中的页面列表中打开随机页面:

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

==========更新==========

谢谢 Tomm.. 。

我编辑了您的代码如下:

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

但是,有时会多次选择相同的随机数/页面。有什么办法可以避免这种情况吗?

How can I make a link open a random page from a list of pages in a colorbox lightbox based on the following code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄断弥空 2024-12-04 15:04:44
$(document).ready(function() {
    $("a.colorbox").click(function() {
        $(this).attr("href","print"+Math.floor(Math.random()*11)+".html");
    });
});

只需将 11 替换为您拥有的任意页数加 1(即,如果您有 page1.html 到 page15.html,请使用 Math.random()*16)。

$(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 (i.e. if you have page1.html to page15.html use Math.random()*16).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文