简体   繁体   English

如何将页码添加到指向锚点的链接?

[英]How do I add a page number to a link to an anchor?

I have in my webpage, several anchors (ie <a name="my-magical-anchor"></a> ) scattered along the page.我的网页中有几个锚点(即<a name="my-magical-anchor"></a> )散布在页面上。 I additionally have several links on my page which point to these anchors (ie <a href="#my-magical-anchor">Go to the Magical Anchor</a> ).我的页面上还有几个指向这些锚点的链接(即<a href="#my-magical-anchor">Go to the Magical Anchor</a> )。 For when the page is printed, I was wondering if it would be possible to modify the text of the link, using CSS or JavaScript, to read something like Go to the Magical Anchor (page 12) to indicate the page number the reader should flip to in the printed document.因为在打印页面时,我想知道是否可以使用 CSS 或 JavaScript 修改链接的文本,以读取类似Go to the Magical Anchor (page 12)以指示读者应该翻转的页码到打印的文档中。

I would like to, if possible, not have to manually assign page breaks, but instead have my content flow across the pages and then update the link text before printing.如果可能,我想不必手动分配分页符,而是让我的内容在页面上流动,然后在打印前更新链接文本。

Thanks.谢谢。

Look at this article and go down to the section titled, "Cross-References": http://www.alistapart.com/articles/boom看看这篇文章,然后转到标题为“交叉引用”的部分: http : //www.alistapart.com/articles/boom

The suggestion is to use target-counter , targeting the page counter, using the href attribute as the target link.建议使用target-counter ,针对page计数器,使用href属性作为目标链接。

a.magical::after {
    content: "(page" target-counter(attr(href), page) ")"
}

The whole article is recommended too.也推荐整篇文章。 Hat tip to Nathan Kot who linked to it.向与之相关联的 Nathan Kot 致敬。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM