1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
---
title: TouchEvent.touches
slug: Web/API/TouchEvent/touches
tags:
- API
- DOM
- DOM Reference
- touch
translation_of: Web/API/TouchEvent/touches
---
<p>{{ APIRef("Touch Events") }}</p>
<h2 id="概要"><font><font>概要</font></font></h2>
<p>一个 {{ domxref("TouchList") }},其会<font><font>列出所有当前在与触摸表面接触的 </font></font>{{ domxref("Touch") }} 对象<font><font>,不管触摸点是否已经改变或其目标元素是在处于 </font></font><code>touchstart </code>阶段<font><font>。</font></font></p>
<p>此属性是 {{readonlyInline}}。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="eval">var <em>touches</em> = <em>touchEvent</em>.touches;
</pre>
<h3 id="Return_Value" name="Return_Value"><font><font>返回值</font></font></h3>
<dl>
<dt><code>touches</code></dt>
<dd>一个 {{ domxref("TouchList") }},其会<font><font>列出所有当前在与触摸表面接触的 </font></font>{{ domxref("Touch") }} 对象<font><font>,不管触摸点是否已经改变或其目标元素是在处于 </font></font><code>touchstart </code>阶段<font><font>。</font></font></dd>
</dl>
<h2 id="示例">示例</h2>
<p><font><font>此示例说明 </font></font>{{domxref("TouchEvent")}}<code> </code><font><font>对象的<font face="consolas, Liberation Mono, courier, monospace"> </font></font></font>{{domxref("TouchEvent.touches")}} <font><font>属性。</font><font>该</font></font>{{domxref("TouchEvent.touches")}} <font><font>属性是一个<font face="consolas, Liberation Mono, courier, monospace"> </font></font></font>{{domxref("TouchList")}}<font><font><font face="consolas, Liberation Mono, courier, monospace"> </font>对象,并包含<font face="consolas, Liberation Mono, courier, monospace"> </font></font></font>{{domxref("Touch")}} <font><font>当前接触表面的每个接触点的对象</font><font>列表</font><font>。</font></font></p>
<p><font><font>在下面的代码片段中,</font></font>{{event("touchstart")}} <font><font>事件处理程序会检查 </font></font>{{domxref("TouchEvent.touches")}}<code> </code><font><font>列表</font><font>的长度,</font><font>以确定激活的触摸点的数量,然后根据触摸点的数量调用不同的处理程序。</font></font></p>
<pre class="brush: js">someElement.addEventListener('touchstart', function(e) {
// Invoke the appropriate handler depending on the
// number of touch points.
switch (e.touches.length) {
case 1: handle_one_touch(e); break;
case 2: handle_two_touches(e); break;
case 3: handle_three_touches(e); break;
default: console.log("Not supported"); break;
}
}, false);
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">评价</th>
</tr>
<tr>
<td>{{SpecName('Touch Events 2','#widl-TouchEvent-touches')}}</td>
<td>{{Spec2('Touch Events 2')}}</td>
<td>不稳定版</td>
</tr>
<tr>
<td>{{SpecName('Touch Events','#widl-TouchEvent-touches')}}</td>
<td>{{Spec2('Touch Events')}}</td>
<td>初始定义</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性"><font><font>浏览器兼容性</font></font></h2>
<p>{{Compat("api.TouchEvent.touches")}}</p>
|