length
read-only property indicates the number of items (touch points) in a given
TouchList
.
var numTouches = touchList.length;
numTouches
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 | 草案 | 非稳定版本。 |
| 触摸事件 | 推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
length
|
Chrome 18 | Edge ≤18 |
Firefox
52
|
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 |
完整支持
不支持