--- title: HTMLElement.click() slug: Web/API/HTMLElement/click translation_of: Web/API/HTMLElement/click ---
{{ APIRef("HTML DOM") }}

HTMLElement.click() 方法可以模擬滑鼠點擊一個元素。

click() 被使用在支援的元素(例如任一 {{HTMLElement("input")}} 元素),便會觸發該元素的點擊事件。事件會冒泡至 document tree(或 event chain)的上層元素,並觸發它們的點擊事件。其中的例外是:click() 方法不會讓 {{HTMLElement("a")}} 元素和接收到真實滑鼠點擊一樣進行頁面跳轉。

語法

elt.click()

規範

Specification Status Comment
{{SpecName('DOM2 HTML', 'html.html#ID-2651361')}} {{Spec2('DOM2 HTML')}} Initial definition

瀏覽器相容性

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 20[3] {{CompatVersionUnknown}} 5[1] {{CompatVersionUnknown}} {{CompatVersionUnknown}}[2] 6[3]
input@file (limited) {{CompatVersionUnknown}} {{CompatVersionUnknown}} 4 {{CompatVersionUnknown}} 12.10 {{CompatVersionUnknown}}
input@file (full) {{CompatVersionUnknown}} {{CompatVersionUnknown}} 4 {{CompatVersionUnknown}} {{CompatNo}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatNo}} {{CompatUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] Prior to Gecko 5.0 {{geckoRelease("5.0")}}, Gecko would not implement the click() 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.

[2] In Presto-based versions of Opera, the click() method will be silently ignored if made on an {{HTMLElement("input")}} with its type attribute set to file and its CSS {{cssxref('display')}} property set to none.

[3] Older versions had HTMLInputElement.click(), and HTMLButtonElement.click() only.