HTMLElement.click()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

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

語法

elt.click()

規範

Specification
HTML
# dom-click-dev

瀏覽器相容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
click

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.