length read-only property indicates the number of items (touch points) in a given TouchList .

句法

var numTouches = touchList.length;
					

返回值

numTouches
The number of touch points in touchList .

范例

This code example illustrates the use of the TouchList 接口的 item 方法和 length 特性。

target = document.getElementById("target");
target.addEventListener('touchstart', function(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
  var touch;
  if (ev.targetTouches.length >= 1)
     touch = ev.targetTouches.item(0);
  else
     touch = ev.touches.item(0);
}, false);
					

规范

规范 状态 注释
Touch Events – Level 2 草案 非稳定版本。
触摸事件 推荐 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
length Chrome 18 Edge ≤18 Firefox 52
52
不支持 18 — 24
IE No Opera 15 Safari No WebView Android Yes Chrome Android Yes Firefox Android 6 Opera Android 14 Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

元数据

  • 最后修改:
  1. 触摸事件
  2. TouchList
  3. 特性
    1. length
  4. 方法
    1. identifiedTouch()
    2. item()
  5. Related pages for Touch Events
    1. 触摸
    2. TouchEvent