如何在 JavaScript 中搜索链接的 href 属性值?
htmljavascriptprogramming scripts更新于 2026/1/10 8:44:17
要在 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>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

