我的 CSS 中的伪类中有一个计数器,类似这样,
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
我想要计数器的计算值。
我尝试过使用
getComputedStyles(document.getElementById("1"), '::before')
但返回部分“counter(section) ”:
,而我试图获取它显示的实际值。这是第 1 部分:
这是我一直在测试的演示 HTML 片段,
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
<h2 id="1">HTML Tutorial</h2>
最佳答案
不幸的是,在当前的 CSS 规范中这是不可能的。了解原因以及该怎么做 in this answer
关于javascript - 如何获取伪元素的计算值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58193425/