HTML - DOM Style 物件 counterIncrement 屬性



HTML DOM Style 物件**counterIncrement**屬性定義了在選擇器每次出現時要增加的計數器的數量。

語法

設定 counterIncrement 屬性
object.style.counterIncrement= "none | id number | initial | inherit";
獲取 counterIncrement 屬性
object.style.counterIncrement;

屬性值

描述
none 這是預設行為,指定不增加任何計數器。
id 數字 id 指定要增加哪個計數器,數字設定在選擇器每次出現時要增加計數器的次數。它的值可以是 0 或負數,預設值為 1。
initial 用於將此屬性設定為其預設值。
inherit 用於繼承其父元素的屬性。

返回值

它返回一個字串值,表示元素的 counterIncrement 屬性。

HTML DOM Style 物件“counterIncrement”屬性示例

以下示例說明了在 h3 元素上設定計數器的屬性。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM Style Object counterIncrement Property
    </title>
    <style>
        h3 {
            counter-increment: level;
        }
        h3:before {
            content: "level " counter(level) " ";
        }
    </style>
</head>
<body>
    <h3 id="inc">HTML DOM Tutorials</h3>
    <h3>HTML DOM Syle Object</h3>
    <h3>counterIncrement Property</h3>
    <h3>Example Code</h3>
    <button onclick="fun()">Click</button>
    <script>
        function fun() {
            document.getElementById("inc")
                .style.counterIncrement = "sublevel";
        }
    </script>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
counterIncrement 是 2 是 12 是 1 是 3 是 9.2
html_dom_style_object_reference.htm
廣告