SVGPointList: clear() 方法

Baseline 已廣泛支援

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

clear() 方法是 SVGPointList 介面的方法,用於移除列表中的所有項。

語法

js
clear()

引數

無。

返回值

無(undefined)。

異常

NoModificationAllowedError DOMException

如果列表是隻讀的,則會丟擲此錯誤。

示例

以下示例顯示了一個包含 <polyline> 元素(具有五個座標對)的 SVG。呼叫 clear() 會清空列表。因此,該折線將不再顯示在 SVG 中。

html
<svg id="svg" viewBox="-10 -10 120 120" xmlns="http://www.w3.org/2000/svg">
  <polyline
    id="example"
    stroke="black"
    fill="none"
    points="50,0 21,90 98,35 2,35 79,90" />
</svg>
js
let example = document.getElementById("example");
example.points.clear();

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGNameList__clear

瀏覽器相容性