我有一个导航栏,我想访问与每个链接关联的不同列表中的随机URL。链接A将访问列表A,链接B将访问列表B,等等。 我一直使用从1997年的JavaScript代码,一条链路的伟大工程:包含在一个js文件带有多个列表的随机URL JS
< --code: - >
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};
function rand(number) {
return Math.ceil(rnd()*number);
};
var item = 0;
var URL = new Array();
URL[item++] = 'listitema.php';
URL[item++] = 'listitemb.php.php';
URL[item++] = 'listitemc.php';
function randomJump() {
var random = rand(item) - 1;
location.href = URL[random];
};
< --end js文件: - >
这是与该访问:
<a href="javascript:randomJump()" onmouseover="self.status='';return true">
尽管此代码非常适用于每页一个链接,我现在需要把它的工作万亩一个链接,每个链接都有一个不同的参考列表。我不知道如何使这个脚本适用于每个链接而不会干扰其他链接。 谢谢。
为什么不使用'Math.random()'而不是自己的函数?如果你需要确保你的本地随机值与服务器上的相同(即相同的算法,相同的种子),通常使用自定义的RNG才有意义... – ThiefMaster