HTML DOM 样式 counterIncrement 属性
htmlweb developmentfront end technology更新于 2024/3/14 2:52:17
HTML DOM 样式 counterIncrement 属性用于增加或减少一个或多个 CSS 计数器的值。通常与 counterReset 和 content 属性一起使用。
以下是语法 −
设置 counterIncrement 属性 −
object.style.counterIncrement = "none|id|initial|inherit"
以上属性值的解释如下 −
| 值 | 描述 |
|---|---|
| none | 这是默认值,计数器不会递增。 |
| idnumber | 用于将特定 ID 的计数器递增给定的数字。默认增量值为 1,也允许使用 0 或负值。 |
| initial | 用于将此属性设置为初始值。 |
| inherit | 继承父级属性值 |
我们来看一个 counterIncrement 属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
ul {
counter-reset: demo_var;
}
li::after {
counter-increment: demo_var 10;
content: " " counter(demo_var) ".";
}
</style>
<script>
function incrementCounterVal(){
document.getElementsByTagName("li")[0].style.counterIncrement="demo_var 2";
document.getElementById("Sample").innerHTML="The counter increment values is now increased by2";
}
</script>
</head>
<body>
<ul>
<li>Demo =</li>
<li>Demo =</li>
<li>Demo =</li>
<li>Demo =</li>
<li>Demo =</li>
<li>Demo =</li>
</ul>
<p>Increase the above list counter Increment value by clicking the below button</p>
<button onclick="incrementCounterVal()">Increase Counter Value</button>
<p id="Sample"></p>
</body>
</html>
输出

点击"增加计数器值"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

