我的CSS伪类中有一个计数器,类似这样,
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
,我想要计数器的计算值。
我尝试使用
getComputedStyles(document.getElementById("1"), '::before')
但是返回Section " counter(section) ":
,而我试图获取它显示的实际值。这是Section 1:
这是我一直在测试的演示HTML代码段,
body {
counter-reset: section;
}
h2::before {
counter-increment: section;
content: "Section " counter(section) ": ";
}
<h2 id="1">HTML Tutorial</h2>