HTML DOM links 集合
document.links 集合返回当期文档所有链接的数组
links 集合计算 <a href=""> 标签和 <area> 标签
浏览器支持
Yes | Yes | Yes | Yes | Yes |
语法
document.links[].property
范例
返回文档的链接数
<img src ="/static/i/html/planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap"> <map name="planetmap"> <area shape="rect" coords="0,0,82,126" href="/static/media/html/sun.html" alt="Sun"> <area shape="circle" coords="90,58,3" href="/static/media/html/mercur.html" alt="Mercury"> <area shape="circle" coords="124,58,8" href="/static/media/html/venus.html" alt="Venus"> </map> <p><a href="/yufei/javascript/">JavaScript 教程</a></p> <p>链接/地址数目: <script> document.write(document.links.length); </script></p>
范例 2
返回文档的第一个链接
<img src ="/static/i/html/planets.gif" width="145" height="126" alt="Planets" usemap ="#planetmap"> <map name="planetmap"> <area id="sun" shape="rect" coords="0,0,82,126" href="/static/media/html/sun.html" alt="Sun"> <area id="mercury" shape="circle" coords="90,58,3" href="/static/media/html/mercur.html" alt="Mercury"> <area id="venus" shape="circle" coords="124,58,8" href="/static/media/html/venus.html" alt="Venus"> </map> <p><a id="javascript" href="/yufei/javascript/">JavaScript 教程</a></p> <p>第一个链接/地址的ID: <script> document.write(document.links[0].id); </script></p>