Home > Web Front-end > JS Tutorial > body text

JS method to randomly generate hyperlink addresses on web pages_javascript skills

WBOY
Release: 2016-05-16 15:33:17
Original
1747 people have browsed it

The example in this article describes how to use JS to randomly generate hyperlink addresses on web pages. Share it with everyone for your reference, the details are as follows:

This is a JavaScript application. Every time the page is refreshed, the link will be automatically changed. Although it is not commonly used, the use of the Javascript random function Math.random() will have a guiding effect.

The screenshot of the running effect is as follows:

The online demo address is as follows:

http://demo.jb51.net/js/2015/js-math-rand-url-show-codes/

The specific code is as follows:

<html>
<head>
<title>在网页上随机产生超链接地址</title>
<script language="javascript">
<!--
  url = new Array();
  url[0] = "http://www.yahoo.com";
  url[1] = "http://www.jb51.net";
  url[2] = "http://www.baidu.com";
  i = Math.random() * url.length;
  i = Math.floor(i);
  str = "<a id='linkID' href='" + url[i] + "'>";
-->
</script>
</head>
<body>
<script language="javascript">
<!--
  document.write(str + "本链接是随机产生的,刷新页面会更换。</a><br>");
  document.write(linkID.href);
//-->
</script>
</body>
</html>

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template