怎么制作一个随机跳转页面的超链接?

怎么制作一个随机跳转页面的超链接?,第1张

建立多个网页,其中一个是跳转页。建立这五个网页1.html2.html3.html4.html5.html

在跳转页加入代码

页面body标签中加 onload元素.

<body onload="javascript:dogo()">

<script>

function dogo(){

var urls = new Array()

urls[0] = "1.HTML"

urls[1] = "2.HTML"

urls[2] = "3.HTML"

urls[3] = "4.HTML"

urls[4] = "5.HTML"

n = Math.floor(Math.random()*5)

location.href= urls[n]

}

</script>

<html>

<head>

<title>blog</title>

<SCRIPT LANGUAGE="JavaScript">

function a(){

setTimeout("b()",1000)//点击按钮一秒钟后跳转到随机页面

}

function b(){//跳转函数

var randompath=parseInt(Math.random()*3)+1//随机得到1到3的整数(1,2,3)

window.location=randompath+".html"

}

</SCRIPT>

</head>

<body>

<input onclick="a()" type="button" value="随机跳转">

</body>

</html>

在body的onload事件中调用a()即可


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7400075.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-05
下一篇2023-04-05

发表评论

登录后才能评论

评论列表(0条)

    保存