📜  HTML 事件属性

📅  最后修改于: 2020-11-02 05:56:56             🧑  作者: Mango

HTML 事件属性

当浏览器对用户操作做出反应时,则称为事件。例如,当您单击提交按钮时,浏览器将显示一个信息框。

在HTML5中,有许多可用的事件属性,可以使用诸如JavaScript之类的编程语言来激活它们。

以下是事件属性表,使用这些属性可以执行多个事件。

Windows事件属性

Windows事件与window对象相关,并且只能与标签。

Attribute Description
onafterprint Executed the script after the document is printed.
onbeforeprint Executed the script before the document is printed.
onbeforeunload Executed the script before a document being unloaded.
onerror Executed the script when an error occurs.
onhashchange Executed the script when the anchor part in URL of the webpage is changed.
onload Executed the script when the webpage is entirely loaded.
onmessage Executed the script when a message event occurs.
onoffline Executed the script when the network connection is disconnected, and browser started working offline.
ononline Executed the script when the browser started working online
onpagehide Executed the script when the current webpage is hidden such as if the user has moved away from the current webpage.
onpageshow Executed the script when the current webpage is focused.
onpopstate Executed the script when the window’s active history is changed.
onresize Executed the script when the window is resized.
onstorage Executed the script when web storage is updated.
onunload Executed the script when the current webpage is unloaded, or window is closed.

表单事件属性

当用户在表单中执行某些操作(例如提交表单,选择输入字段等)时,发生表单事件。

表单事件可以与任何元素一起使用,但是这些事件主要与HTML表单元素一起使用。

以下是所有表单事件属性的列表:

Attribute Description
onblur Executed the script when form element loses the focus.
onchange Executed the script when the value of the element is changed.
onfocus Trigger an event when the element gets focused.
oninput Executed the script when the user enters input to the element.
oninvalid Executed the script when the element does not satisfy its predefined constraints.
onreset Triggers the event when user reset the form element values.
onsearch Triggers the event when a search field receives some input.
onselect Triggers the event when the user has selected some text.
onsubmit Triggers the event when a form is submitted.

键盘事件属性

用户与键盘交互时发生键盘事件。以下是键盘事件的列表。

Attribute Description
onkeydown Triggers the event when the user presses down a key on the keyboard.
onkeypress Trigger the event when the user presses the key which displays some character.
onkeyup Trigger the event when the user releases the currently pressed key.

鼠标事件属性

Attribute Description
onclick Trigger the event when the mouse clicks on the element.
ondblclick Trigger the event when mouse double-click occurs on the element.
onmousedown Trigger the event when the mouse button is pressed on the element.
onmousemove Trigger the event when the mouse pointer moves over the element.
onmouseout Trigger the event when the mouse moves outside the element.
onmouseover Trigger the event when the mouse moves onto the element.
onmouseup Trigger the event when the mouse button is released.
onmousewheel Deprecated. Use the onwheel attribute.
onwheel Trigger the event when the mouse wheel rolls up or down on the element

剪贴板事件属性

Attribute Description
oncopy Trigger the event when the user copies the content to the system clipboard.
oncut Trigger the event when the content of an element is cut and copy to the clipboard.
onpaste Trigger the event when the user pastes some content in an element.

媒体事件属性

Attribute Description
onabort Executed the script when media playback is aborted.
oncanplay Executed the script when the media file is ready to play.
oncanplaythrough Executed the script when the media file is ready to play without buffering or stopping.
oncuechange Executed the script text cue of element is changed.
ondurationchange Executed the script when the media file duration is changed.
onemptied Executed the script if media occurs some fatal error, and the file becomes unavailable.
onended Executed the script when the media file occurs its end point.
onerror Executed the script when some error occurred while fetching the media data.
onloadeddata Executed the script when media data is loaded.
onloadedmetadata Executed the script when metadata of media file is loaded.
onloadstart Executed the script when loading of media file starts.
onpause Executed the script when media playback is paused.
onplay Executed the script when media file ready to play after being paused.
onplaying Executed the script when media file is started playing.
onprogress Executed the script when the browser is in the process of getting the media data.
onratechange Executed the script when playback speed changed.
onseeked Executed the script when seek operation is ended and seeking attribute is set to false.
onseeking Executed the script when seek operation is active and seeking attribute is set to true.
onstalled Executed the script when browser unexpectedly stopped fetching the data media.
onsuspend Executed the script if fetching of media data is intentionally stopped.
ontimeupdate Executed the script when playback position is changed, such as if a user fasts forward the track.
onvolumechange Executed the script when media volume is changed (muted or unmuted).
onwaiting Executed the script if playback pause to wait for loading more data.