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

浏览器兼容性