开发者社区> 问答> 正文

document.anchors为什么不会返回<a href='#'>?

<a name='xxx'>与<a href='xxx'>有什么区别吗?
全选复制放进笔记<!DOCTYPE html>
<html>
<body>

<a name="html">HTML Tutorial</a><br>
<a name="css">CSS Tutorial</a><br>
<a name="xml">XML Tutorial</a>

<p>innerHTML of the first anchor:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>

</body>
</html>

展开
收起
a123456678 2016-03-11 18:34:49 1932 0
1 条回答
写回答
取消 提交回答
  • For reasons of backwards compatibility, the returned set of anchors only contains those anchors created with the name attribute, not those created with the id attribute.
    所以document.anchors只会返回有name属性的节点。

    另外,这种方式已经废弃,最好不要使用

    This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.

    2019-07-17 18:59:51
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载