摘要

返回 元素 ( EventTarget ) on which the touch contact started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element or even been removed from the document. Note that if the target element is removed from the document, events will still be targeted at it, and hence won't necessarily bubble up to the window or document anymore. If there is any risk of an element being removed while it is being touched, the best practice is to attach the touch listeners directly to the target.

句法

var el = touchPoint.target;
					

返回值

el
The target element of the 触摸 对象。

范例

This example illustrates how to access the 触摸 对象的 Touch.target property. The Touch.target property is an 元素 ( EventTarget ) on which a touch point is started when contact is first placed on the surface.

In following simple code snippet, we assume the user initiates one or more touch contacts on the source element. When the touchstart event handler for this element is invoked, each touch point's Touch.target property is accessed via the event's TouchEvent.targetTouches 列表。

// Register a touchmove listener for the 'source' element
var src = document.getElementById("source");
src.addEventListener('touchstart', function(e) {
  // Iterate through the touch points that were activiated
  // for this element.
  for (var i=0; i < e.targetTouches.length; i++) {
    console.log("touchpoint[" + i + "].target = " + e.targetTouches[i].target);
  }
}, 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
target Chrome 22 Edge ≤18 Firefox 52
52
Touch events support has been fixed and reenabled in Windows desktop platforms.
不支持 18 — 24
Web compatibility issues seen in bug 888304 .
IE No Opera Yes Safari No WebView Android Yes Chrome Android Yes Firefox Android 6 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

元数据

  • 最后修改: