gpt4 book ai didi

html - H1..H6 标签中 'name' 属性的用途是什么?

转载 作者:太空宇宙 更新时间:2023-11-04 14:36:09 25 4
gpt4 key购买 nike

据我理解,id属性作为整个文档中某个标签的唯一标识,而name作为标识(不一定在文档中唯一)与一些数据一起发送到服务器。

然而,使用 MDN 页面中的元素检查器(以 this 为例),我注意到所有文章的 h1..h6 标签存在于导航树中的标签具有 name 属性,并且它们与各自标签的 id 相同。在这种情况下,这些属性的用途是什么?它们是否用于构建导航树?

最佳答案

它很可能用于书签 anchor 以跳转到页面的特定部分。在过去,您会使用 name 属性来定位元素,但今天您使用 ID。所以它可能只是为了向后兼容而保留的。

如果你 checkout https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Clicking_and_focus ,你会看到解释:

name (HTML 4 only, Obsolete since HTML5) This attribute is required in an anchor defining a target location within a page. A value for name is similar to a value for the id core attribute and should be an alphanumeric identifier unique to the document. Under the HTML 4.01 specification, id and name both can be used with the <a> element as long as they have identical values. Usage note: This attribute is obsolete in HTML5, use global attribute id instead.

关于html - H1..H6 标签中 'name' 属性的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25813113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com