📜  HTML-事件参考

📅  最后修改于: 2020-12-16 06:00:00             🧑  作者: Mango


用户访问您的网站时,他们会执行诸如单击各种链接,将鼠标悬停在文本和图像上等操作。这些都是我们在JavaScript和VBScript术语中称为事件的示例。

我们可以使用JavaScript或VBScript编写事件处理程序,并可以指定针对这些事件采取的某些操作。尽管这些是事件,但是它们将被指定为HTML标签的属性。

HTML 4.01规范定义了19个事件,但后来HTML-5添加了许多其他事件,我们在这里列出了这些事件-

窗口事件属性

在旧版HTML中引入了以下事件,但所有标记为的标记HTML-5是HTML-5的一部分。

Events HTML-5 Description
onafterprint HTML-5 Triggers after a document is printed
onbeforeprint HTML-5 Triggers before a document is printed
onbeforeonload HTML-5 Triggers before a document loads
onerror HTML-5 Triggers when an error occurs
onhaschange HTML-5 Triggers when a document has changed
onload Triggers when a document loads
onmessage HTML-5 Triggers when a message is triggered
onoffline HTML-5 Triggers when a document goes offline
ononline HTML-5 Triggers when a document comes online
onpagehide HTML-5 Triggers when a window is hidden
onpageshow HTML-5 Triggers when a window becomes visible
onpopstate HTML-5 Triggers when a window’s history changes
onredo HTML-5 Triggers when a document performs a redo
onresize HTML-5 Triggers when a window is resized
onstorage HTML-5 Triggers when a document loads
onundo HTML-5 Triggers when a document performs an undo
onunload Triggers when a user leaves the document

表单事件

以下标记已在旧版HTML中引入,但所有标记为的标记HTML-5是HTML-5的一部分。

Events HTML-5 Description
onblur Triggers when a window loses focus
onchange Triggers when an element changes
oncontextmenu HTML-5 Triggers when a context menu is triggered
onfocus Triggers when a window gets focus
onformchange HTML-5 Triggers when a form changes
onforminput HTML-5 Triggers when a form gets user input
oninput HTML-5 Triggers when an element gets user input
oninvalid HTML-5 Triggers when an element is invalid
onreset Triggers when a form is reset
onselect Triggers when an element is selected
onsubmit Triggers when a form is submitted

键盘事件

Events HTML-5 Description
onkeydown Triggers when a key is pressed
onkeypress Triggers when a key is pressed and released
onkeyup Triggers when a key is released

鼠标事件

以下标记已在旧版HTML中引入,但所有标记为的标记HTML-5是HTML-5的一部分。

Events HTML-5 Description
onclick Triggers on a mouse click
ondblclick Triggers on a mouse double-click
ondrag HTML-5 Triggers when an element is dragged
ondragend HTML-5 Triggers at the end of a drag operation
ondragenter HTML-5 Triggers when an element has been dragged to a valid drop target
ondragleave HTML-5 Triggers when an element leaves a valid drop target
ondragover HTML-5 Triggers when an element is being dragged over a valid drop target
ondragstart HTML-5 Triggers at the start of a drag operation
ondrop HTML-5 Triggers when a dragged element is being dropped
onmousedown Triggers when a mouse button is pressed
onmousemove Triggers when the mouse pointer moves
onmouseout Triggers when the mouse pointer moves out of an element
onmouseover Triggers when the mouse pointer moves over an element
onmouseup   Triggers when a mouse button is released
onmousewheel HTML-5 Triggers when the mouse wheel is being rotated
onscroll HTML-5 Triggers when an element’s scrollbar is being scrolled

媒体活动

以下标记已在旧版HTML中引入,但所有标记为的标记HTML-5是HTML-5的一部分。

Events HTML-5 Description
onabort Triggers on an abort event
oncanplay HTML-5 Triggers when a media can start play, but might has to stop for buffering
oncanplaythrough HTML-5 Triggers when a media can be played to the end, without stopping for buffering
ondurationchange HTML-5 Triggers when the length of a media is changed
onemptied HTML-5 Triggers when a media resource element suddenly becomes empty.
onended HTML-5 Triggers when a media has reached the end
onerror HTML-5 Triggers when an error occurs
onloadeddata HTML-5 Triggers when media data is loaded
onloadedmetadata HTML-5 Triggers when the duration and other media data of a media element is loaded
onloadstart HTML-5 Triggers when the browser starts loading the media data
onpause HTML-5 Triggers when media data is paused
onplay HTML-5 Triggers when media data is going to start playing
onplaying HTML-5 Triggers when media data has started playing
onprogress HTML-5 Triggers when the browser is fetching the media data
onratechange HTML-5 Triggers when the playing rate of media data has changed
onreadystatechange HTML-5 Triggers when the ready-state changes
onseeked HTML-5 Triggers when the seeking attribute of a media element is no longer true, and the seeking has ended
onseeking HTML-5 Triggers when the seeking attribute of a media element is true, and the seeking has begun
onstalled HTML-5 Triggers when there is an error in fetching media data
onsuspend HTML-5 Triggers when the browser has been fetching media data, but stopped before the entire media file was fetched
ontimeupdate HTML-5 Triggers when media changes its playing position
onvolumechange HTML-5 Triggers when a media changes the volume, also when volume is set to “mute”
onwaiting HTML-5 Triggers when media has stopped playing, but is expected to resume