# 锚点到标题并不总是有效

**URL:** <https://meta.discourse.org/t/anchors-to-headings-do-not-always-work/208356>\
**Category:** Bug\
**Created:** [2021年十一月5日 11:45 UTC](https://meta.discourse.org/t/anchors-to-headings-do-not-always-work/208356 "2021-11-05T11:45:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eisprinzessin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eisprinzessin/32/234408_2.png) [@eisprinzessin](https://meta.discourse.org/u/eisprinzessin)\
**Post date:** [2021年十一月5日 11:45 UTC](https://meta.discourse.org/t/anchors-to-headings-do-not-always-work/208356/1 "2021-11-05T11:45:30Z")

</div>

> [@eisprinzessin](#):
>
> 请考虑将[类别限制](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#3-category-restrictions-7)移至标签页面。

我一直疑惑为什么这个链接无法跳转到对应的锚点。如果标题不属于枚举列表，链接是有效的：

- [顶级标签](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#top-level-tags-3)
- [父子标签关系](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#parent-child-tag-relationships-4)
- [结果](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#the-result-5)
- [可见性和使用限制](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#visibility-and-usage-restrictions-6)

但在以下情况中链接失效，最终会跳转到主题顶部：

- [1. 前置条件](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#1-pre-reqs-1)
- [2. 标签组](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#2-tag-groups-2)
- [3. 类别限制](https://meta.discourse.org/t/how-to-create-tag-structures-tag-category-restrictions-tag-groups-and-tag-relationships/48260#3-category-restrictions-7)

不过，我无法在新线程中复现此问题。也许您只需重新生成那条五年前的帖子即可。

---

<div class="post-metadata">

**Author:** ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)\
**Post date:** [2021年十一月5日 14:35 UTC](https://meta.discourse.org/t/anchors-to-headings-do-not-always-work/208356/2 "2021-11-05T14:35:18Z")

</div>

我可以在新主题上复现此问题，似乎以数字开头的标题由于某种原因无法正常工作。如果在同一页面上手动将 ID 添加到 URL 中，它们可以工作，但从其他地方链接时则无法工作。

---

<div class="post-metadata">

**Author:** ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)\
**Post date:** [2021年十一月8日 18:46 UTC](https://meta.discourse.org/t/anchors-to-headings-do-not-always-work/208356/4 "2021-11-08T18:46:50Z")

</div>

以数字开头的标题被分配了以数字开头的 ID，这是无效的。我合并了一个 PR 来解决这个问题：

> <https://github.com/discourse/discourse/pull/14840>
>
> IDs must start with a letter.

---

<div class="post-metadata">

**Author:** ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)\
**Post date:** [2021年十一月9日 21:27 UTC](https://meta.discourse.org/t/anchors-to-headings-do-not-always-work/208356/5 "2021-11-09T21:27:48Z")

</div>


