Home  >  Article  >  Web Front-end  >  JavaScript method to get the number of hyperlinks in the page_javascript skills

JavaScript method to get the number of hyperlinks in the page_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:33:192483browse

The example in this article describes the method of using JavaScript to obtain the number of hyperlinks in the page. Share it with everyone for your reference, the details are as follows:

Here is a demonstration of using JavaScript to obtain the number of hyperlinks on a page. Friends who are interested can learn from it.

The screenshot of the running effect is as follows:

The online demo address is as follows:

http://demo.jb51.net/js/2015/js-total-link-num-codes/

The specific code is as follows:

<html>
<head>
<title>JavaScript取得页面的超链接数</title>
<script language="javascript">
<!--
 function getLinks(){
  links = document.all.tags("A")
  total = links.length;
  alert("本页面共有" + total + "个超链接!");
 }
-->
</script>
</head>
<body onLoad="getLinks()">
<a href="#">a</a>
<a href="#">b</a>
<a href="#">c</a>
</body>
</html>

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

Statement:
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