Categories: DOM对象tips

HTML DOM links 集合 | HTML DOM Document 对象

返回到:DOM 对象:HTML DOM Document 对象

定义和用法

links 集合返回当前文档所有链接的数组。

提示: links 集合计算 <a href=””> 标签和 <area> 标签。

语法

document.links[].property

浏览器支持:

所有主要浏览器都支持 links 集合

实例

返回文档的链接数:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程网(web176.com)</title>
</head>
<body>

<img src ="/images/logo.svg" width="145" height="126" alt="Planets" usemap ="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
<p><a href="/js/">JavaScript 教程</a></p>
<p>链接/地址数目:
<script>
document.write(document.links.length);
</script></p>

</body>
</html>

返回文档的第一个链接:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程网(web176.com)</title>
</head>
<body>

<img src ="/images/logo.svg" width="145" height="126" alt="Planets" usemap ="#planetmap">
<map name="planetmap">
<area id="sun" shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area id="mercury" shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area id="venus" shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
<p><a id="javascript" href="/js/">JavaScript 教程</a></p>
<p>第一个链接/地址的ID:
<script>
document.write(document.links[0].id);
</script></p>

</body>
</html>
terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

4 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

2 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

3 周 ago