TouchList: length 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

length 只讀屬性表示給定 TouchList 中項(觸控點)的數量。

touchList 中的觸控點數量。

示例

此程式碼示例說明了如何使用 TouchList 介面的 item 方法和 length 屬性。

js
const target = document.getElementById("target");

target.addEventListener("touchstart", (ev) => {
  // If this touchstart event started on element target,
  // set touch to the first item in the targetTouches list;
  // otherwise set touch to the first item in the touches list
  const touch =
    ev.targetTouches.length >= 1
      ? ev.targetTouches.item(0)
      : ev.touches.item(0);
});

規範

規範
觸控事件
# dom-touchlist-length

瀏覽器相容性