JavaScript获取网页中第一个链接ID的方法

下面的JS代码通过document.links获得网页中的所有超级链接数组,然后获得第一个链接的ID属性

<!DOCTYPE html> <html> <body> <h1>sharejs.com</h1> <img src ="https://www.jb51.net/planets.gif" alt="Planets" usemap ="#planetmap"> <map> <area shape="rect" coords="0,0,82,126" href="https://www.jb51.net/sun.htm" alt="Sun"> <area shape="circle" coords="90,58,3" href="https://www.jb51.net/mercur.htm" alt="Mercury"> <area shape="circle" coords="124,58,8" href="https://www.jb51.net/venus.htm" alt="Venus"> </map> <p><a href="https://www.jb51.net/js/">JavaScript Tutorial</a> </p> <p>Id of first area/link: <script> document.write(document.links[0].id); </script></p> </body> </html>

希望本文所述对大家的javascript程序设计有所帮助。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgjsds.html