如何在 JavaScript 中搜索链接的 href 属性值?
htmljavascriptprogramming scripts
要在 JavaScript 中获取链接的 href 属性值,请使用 href 属性。它会在 JavaScript 中为您提供链接文档的 URL。
示例
您可以尝试运行以下代码来获取链接的 href 属性值。
<!DOCTYPE html> <html> <body> <p><a id="anchorid" href="https://www.qries.com/">Qries</a></p> <script> var myLink = document.getElementById("anchorid").href; document.write("Link: "+myLink); </script> </body> </html>