在灯箱(colorbox)中打开随机页面
如何根据以下代码使链接从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将 11 替换为您拥有的任意页数加 1(即,如果您有 page1.html 到 page15.html,请使用 Math.random()*16)。
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).