📅  最后修改于: 2020-12-16 06:00:00             🧑  作者: Mango
用户访问您的网站时,他们会执行诸如单击各种链接,将鼠标悬停在文本和图像上等操作。这些都是我们在JavaScript和VBScript术语中称为事件的示例。
我们可以使用JavaScript或VBScript编写事件处理程序,并可以指定针对这些事件采取的某些操作。尽管这些是事件,但是它们将被指定为HTML标签的属性。
HTML 4.01规范定义了19个事件,但后来HTML-5添加了许多其他事件,我们在这里列出了这些事件-
在旧版HTML中引入了以下事件,但所有标记为的标记是HTML-5的一部分。
Events | HTML-5 | Description |
---|---|---|
onafterprint | Triggers after a document is printed | |
onbeforeprint | Triggers before a document is printed | |
onbeforeonload | Triggers before a document loads | |
onerror | Triggers when an error occurs | |
onhaschange | Triggers when a document has changed | |
onload | Triggers when a document loads | |
onmessage | Triggers when a message is triggered | |
onoffline | Triggers when a document goes offline | |
ononline | Triggers when a document comes online | |
onpagehide | Triggers when a window is hidden | |
onpageshow | Triggers when a window becomes visible | |
onpopstate | Triggers when a window’s history changes | |
onredo | Triggers when a document performs a redo | |
onresize | Triggers when a window is resized | |
onstorage | Triggers when a document loads | |
onundo | Triggers when a document performs an undo | |
onunload | Triggers when a user leaves the document |
以下标记已在旧版HTML中引入,但所有标记为的标记是HTML-5的一部分。
Events | HTML-5 | Description |
---|---|---|
onblur | Triggers when a window loses focus | |
onchange | Triggers when an element changes | |
oncontextmenu | Triggers when a context menu is triggered | |
onfocus | Triggers when a window gets focus | |
onformchange | Triggers when a form changes | |
onforminput | Triggers when a form gets user input | |
oninput | Triggers when an element gets user input | |
oninvalid | 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的一部分。
Events | HTML-5 | Description |
---|---|---|
onclick | Triggers on a mouse click | |
ondblclick | Triggers on a mouse double-click | |
ondrag | Triggers when an element is dragged | |
ondragend | Triggers at the end of a drag operation | |
ondragenter | Triggers when an element has been dragged to a valid drop target | |
ondragleave | Triggers when an element leaves a valid drop target | |
ondragover | Triggers when an element is being dragged over a valid drop target | |
ondragstart | Triggers at the start of a drag operation | |
ondrop | 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 | Triggers when the mouse wheel is being rotated | |
onscroll | Triggers when an element’s scrollbar is being scrolled |
以下标记已在旧版HTML中引入,但所有标记为的标记是HTML-5的一部分。
Events | HTML-5 | Description |
---|---|---|
onabort | Triggers on an abort event | |
oncanplay | Triggers when a media can start play, but might has to stop for buffering | |
oncanplaythrough | Triggers when a media can be played to the end, without stopping for buffering | |
ondurationchange | Triggers when the length of a media is changed | |
onemptied | Triggers when a media resource element suddenly becomes empty. | |
onended | Triggers when a media has reached the end | |
onerror | Triggers when an error occurs | |
onloadeddata | Triggers when media data is loaded | |
onloadedmetadata | Triggers when the duration and other media data of a media element is loaded | |
onloadstart | Triggers when the browser starts loading the media data | |
onpause | Triggers when media data is paused | |
onplay | Triggers when media data is going to start playing | |
onplaying | Triggers when media data has started playing | |
onprogress | Triggers when the browser is fetching the media data | |
onratechange | Triggers when the playing rate of media data has changed | |
onreadystatechange | Triggers when the ready-state changes | |
onseeked | Triggers when the seeking attribute of a media element is no longer true, and the seeking has ended | |
onseeking | Triggers when the seeking attribute of a media element is true, and the seeking has begun | |
onstalled | Triggers when there is an error in fetching media data | |
onsuspend | Triggers when the browser has been fetching media data, but stopped before the entire media file was fetched | |
ontimeupdate | Triggers when media changes its playing position | |
onvolumechange | Triggers when a media changes the volume, also when volume is set to “mute” | |
onwaiting | Triggers when media has stopped playing, but is expected to resume |