gpt4 book ai didi

javascript - 是否可以访问由 css :before rule? 生成的内容

转载 作者:数据小太阳 更新时间:2023-10-29 03:54:41 24 4
gpt4 key购买 nike

我正在尝试使用 html5 和 css counters对文档中的数字进行编号。图编号 css 工作正常,但我需要能够生成包含图编号的交叉引用。

有没有办法通过 javascript 访问这些值?我使用的计数器代码是:

body { counter-reset: section; }
section { counter-reset: figure;
counter-increment: section; }
section section { counter-reset: section; }
section > h1:before { content: counters(section, '.'); }
.figure > .caption:before {
counter-increment: figure;
content: 'Figure ' counters(section, '.') '-' counter(figure); }
section > h1:before, .figure > .caption:before { margin-right: .5em; }

最佳答案

根据 this article :

Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

换句话说,看起来 content CSS 属性只是向页面添加文本“样式”,而不影响文档结构。 DOM 不知道这种样式,因此 Javascript 无法访问它。

关于javascript - 是否可以访问由 css :before rule? 生成的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2358107/

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