
要在JavaScript中获取链接的href属性值,请使用href属性。它可以在JavaScript中给出链接文档的URL。
示例
您可以尝试运行以下代码以获取链接的href属性值。
在线演示
<!DOCTYPE html>
<html>
<body>
<p><a id="anchorid" href="https://www.qries.com/">Qries</a></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/c1c2c2ed740f" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">Java免费学习笔记(深入)</a></a>”;</p>
<script>
var myLink = document.getElementById("anchorid").href;
document.write("Link: "+myLink);
</script>
</body>
</html>











