blob: 123206ca2fda88ed236a767a5055d4473ed4ca78 (
plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
---
title: HTMLElement.click()
slug: Web/API/HTMLElement/click
translation_of: Web/API/HTMLElement/click
---
<div>
<div>{{ APIRef("HTML DOM") }}</div>
</div>
<p><code><strong>HTMLElement.click()</strong></code> 方法可以模擬滑鼠點擊一個元素。</p>
<p>當 <code>click()</code> 被使用在支援的元素(例如任一 {{HTMLElement("input")}} 元素),便會觸發該元素的點擊事件。事件會冒泡至 document tree(或 event chain)的上層元素,並觸發它們的點擊事件。其中的例外是:<code>click()</code> 方法不會讓 {{HTMLElement("a")}} 元素和接收到真實滑鼠點擊一樣進行頁面跳轉。</p>
<h2 id="語法">語法</h2>
<pre class="syntaxbox"><em>elt</em>.click()</pre>
<h2 id="規範">規範</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('DOM2 HTML', 'html.html#ID-2651361')}}</td>
<td>{{Spec2('DOM2 HTML')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari (WebKit)</th>
</tr>
<tr>
<td>Basic support</td>
<td>20<sup>[3]</sup></td>
<td>{{CompatVersionUnknown}}</td>
<td>5<sup>[1]</sup></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}<sup>[2]</sup></td>
<td>6<sup>[3]</sup></td>
</tr>
<tr>
<td><code>input@file (limited)</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>4</td>
<td>{{CompatVersionUnknown}}</td>
<td>12.10</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>input@file (full)</code></td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>4</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatNo}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Edge</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Phone</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatNo}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<p>[1] Prior to Gecko 5.0 {{geckoRelease("5.0")}}, Gecko would not implement the <code>click()</code> method on other elements that might be expected to respond to mouse clicks, such as links ({{HTMLElement("a")}} elements), nor would it necessarily fire the click event of other elements.</p>
<p>[2] In Presto-based versions of Opera, the <code>click()</code> method will be silently ignored if made on an {{HTMLElement("input")}} with its <strong><code>type</code> </strong>attribute set to <code>file</code> and its <a href="/en-US/docs/Web/CSS">CSS</a> {{cssxref('display')}} property set to <code>none</code>.</p>
<p>[3] Older versions had <code>HTMLInputElement.click()</code>, and <code>HTMLButtonElement.click()</code> only.</p>
|