CharacterData:length 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

只讀的 CharacterData.length 屬性返回包含資料中的字元數,為一個正整數。

一個正整數,表示 CharacterData.data 字串的長度。

示例

注意: CharacterData 是一個抽象介面。下面的示例使用實現了它的具體介面 Text

html
Length of the string in the <code>Text</code> node: <output></output>
js
const output = document.querySelector("output");
const textNode = new Text("This text has been set using 'textNode.data'.");

output.value = textNode.length;

規範

規範
DOM
# dom-characterdata-length

瀏覽器相容性