SVGTextContentElement: getNumberOfChars() 方法

Baseline 已廣泛支援

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

SVGTextContentElement 介面的 getNumberOfChars() 方法表示當前元素中用於渲染的可定址字元的總數,無論它們是否會被渲染。

語法

js
getNumberOfChars()

引數

無。

返回值

一個 long。

示例

計算文字元素中的字元數

html
<svg width="300" height="100">
  <text id="exampleText" x="10" y="50">Hello, SVG World!</text>
</svg>
js
const textElement = document.getElementById("exampleText");

// Get the number of characters in the text element
const charCount = textElement.getNumberOfChars();

console.log(charCount); // Output: 17

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGTextContentElement__getNumberOfChars

瀏覽器相容性