2023-01-06T09:40:58.png

js

 document.write("链接数为:" +  
                  document.links.length); 

完整html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>使用JavaScript显示html中存在的链接数</title>
</head> 
  
<body> 
<a href="#">链接1</a> 
<a href = "www.html.cn">链接2</a> 
<a href="www.html.cn/qa/javascript">链接3</a> <br /><br />
  
<a href="www.html.cn/qa/javascript">链接3</a> <br /><br />
  
<a href="www.html.cn/qa/javascript">链接3</a> <br /><br />
  
<script type="text/javascript"> 
  document.write("链接数为:" +  
                  document.links.length); 
</script> 
  
</body> 
</html>

转载:JavaScript计算html中存在的链接数_qq_43067585的博客-CSDN博客
https://blog.csdn.net/qq_43067585/article/details/107280422