Html 如何使一个超链接提供不同的页面?
我正在尝试设置一个超链接,每次单击一个URL列表,它都会随机打开一个不同的网页。有人知道要实现这一点,首先应该使用什么函数吗?像这样Html 如何使一个超链接提供不同的页面?,html,Html,我正在尝试设置一个超链接,每次单击一个URL列表,它都会随机打开一个不同的网页。有人知道要实现这一点,首先应该使用什么函数吗?像这样 <!DOCTYPE html> <html> <head> <script> var links = ['http://google.com', 'http://facebook.com'] function GoToSomeAddress() { window.open(links[getRandomIn
<!DOCTYPE html>
<html>
<head>
<script>
var links = ['http://google.com', 'http://facebook.com']
function GoToSomeAddress() {
window.open(links[getRandomInt(0, 1)]);
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
</head>
<body>
The content of the body element is displayed in your browser.
<a href="" onclick="GoToSomeAddress();return false;">Take me on an adventure</a>
</body>
</html>
到目前为止你做了什么?一个很好的开始功能?有一个非常常用于begin,试试看,也许可以用JavaScript或服务器端脚本(如PHP等)完成。但不仅仅是用html。getRandomInt应该获得链接大小并使用它们,不需要参数。这很完美,谢谢!我在网上找了一个这样的例子,但没有找到。@O.Rares这是Mozilla为随机数范围提供的代码,显然你可以重构和移动,但这是基本的模板。