Event Attributes

Global Event Attributes (全局事件属性)

An event occurs when the browser reacts to a particular action of the user. The user generates an event when clicking on a mouse, playing video, uploading a document or an image, or performing other actions on a website. (当浏览器对用户的特定操作做出反应时,就会发生事件。用户在单击鼠标、播放视频、上传文档或图像或在网站上执行其他操作时生成事件。)

To react to an event, a handler is assigned to it. A handler is a way to run script (e.g., JavaScript) in case of user actions. There are many ways of attaching a handler, and one of them is setting it in HTML with attributes. (要对事件做出反应,将为其分配一个处理程序。处理程序是在用户操作的情况下运行脚本(例如JavaScript )的一种方式。附加处理程序的方法有很多,其中一种是将其设置为带有属性的HTML。)

Below, you can find a table of event attributes used to initiate specific actions. (在下面,您可以找到用于启动特定操作的事件属性表。)

Window Events Attributes

Window Events Attributes (窗口事件属性)

Window events are triggered for the window object. The attributes are applicable only to the <body> tag.

AttributeDescription
onafterprintExecuted when the document is printed.
New attribute in HTML5.
onbeforeprintExecuted before the document is printed.
New attribute in HTML5.
onbeforeunloadExecuted when the document is about to get unloaded (when a user is about to quit the page before it is loaded).
New attribute in HTML5.
onblurExecuted when a window loses focus.
onerrorExecuted when an error occurs when downloading the document.
New attribute in HTML5.
onhashchangeExecuted when the anchor in URL of a web page is changed (anchor comes after #).
New attribute in HTML5.
onloadExecuted when content of a web page (images, CSS styles and scripts) is entirely loaded.
onmessageExecuted when a message is triggered.
New attribute in HTML5.
onofflineExecuted when the browser works offline.
New attribute in HTML5.
ononlineExecuted when the browser works online.
New attribute in HTML5.
onpagehideExecuted when a user go away from the web page.
New attribute in HTML5.
onpageshowExecuted when a user navigates to a web page.
New attribute in HTML5.
onpopstateExecuted when the window’s history is changed.
New attribute in HTML5.
onredoExecuted when a “Redo” option is used ( the last action is reversed).
New attribute in HTML5.
onresizeExecuted when a window is resized.
New attribute in HTML5.
onstorageExecuted when a web storage is updated.
New attribute in HTML5.
onundoExecuted when the last action is cancelled (“undo” command).
New attribute in HTML5.
onunloadExecuted when a web page is unloaded (closed).
New attribute in HTML5.

Form Events Attributes

Form Events Attributes (表单事件属性)

An event that can occur within a form is called a form event. Form events happen when a user opens or closes a form, moves between forms, or works with data on a form. (可以在表单中发生的事件称为表单事件。表单事件发生在用户打开或关闭表单、在表单之间移动或处理表单上的数据时。)

Form events attributes can be applied to all HTML elements, but they are generally used with HTML forms elements. (表单事件属性可以应用于所有HTML元素,但它们通常与HTML表单元素一起使用。)

AttributeDescription
onblurExecuted when a form element loses focus.
onchangeExecuted when the value of the element is changed.
oncontextmenuExecuted when the context menu is shown.
New attribute in HTML5.
onfocusExecuted when an element gets focus.
oninputExecuted when an element gets user input.
New attribute in HTML5.
oninvalidExecuted if an input element is invalid.
New attribute in HTML5.
onresetExecuted when a form is reset (all controls within the form are set to their initial values).
New attribute in HTML5.
onsearchExecuted when the user writes something in a search field (for <input=“search”>).
onselectExecuted when some text is selected in an element.
onsubmitExecuted when a form is sent.

Keyboard Events Attributes

Keyboard Events Attributes (键盘事件属性)

The keyboard event attributes can be applied to all HTML elements. (键盘事件属性可以应用于所有HTML元素。)

AttributeDescription
onkeydownExecuted when the user is pressing any key on the keyboard.
onkeypressExecuted when the user has pressed a key on the keyboard.
(doesn’t work with Alt, Ctrl, Shift, Esc, PrScr).
onkeyupExecuted when a pressed key is released.

Mouse Event Attributes

Mouse Event Attributes (鼠标事件属性)

Mouse events occur when the mouse interacts with the HTML document. The attributes can be applied to all HTML elements. (鼠标与HTML文档交互时发生鼠标事件。属性可以应用于所有HTML元素。)

AttributeDescription
onclickExecuted when a mouse-button is clicked.
ondblclickExecuted when a mouse-button is clicked twice.
ondragExecuted when an element is being dragged.
New attribute in HTML5.
ondragendExecuted when an element has been dragged.
New attribute in HTML5.
ondragenterExecuted when a dragged element enters a valid drop target.
New attribute in HTML5.
ondragleaveExecuted when a dragged element leaves a valid drop target.
New attribute in HTML5.
ondragoverExecuted when a dragged element being dragged over a valid drops target (every few hundred milliseconds).
New attribute in HTML5.
ondragstartExecuted when the user starts dragging an element.
New attribute in HTML5.
ondropExecuted when the user drops dragging an element.
New attribute in HTML5.
onmousedownExecuted when a mouse button is pressed.
onmousemoveExecuted when the mouse pointer is moved onto the element.
onmouseoutExecuted when the mouse pointer moves out of an element.
onmouseoverExecuted when the mouse pointer is moved onto an element.
onmouseupExecuted when a mouse button is released.
onmousewheelExecuted when the mouse wheel rolls up or down over an element.
Obsolete attribute (use onwheel attribute instead).
onscrollExecuted when an element’s scrollbar is being scrolled.
New attribute in HTML5.
onwheelExecuted when the mouse wheel rolls up or down over an element.
New attribute in HTML5.

Clipboard Event Attributes

Clipboard Event Attributes (剪贴板事件属性)

AttributeDescription
oncopyExecuted when the content of an element is copied.
oncutExecuted when the content of an element is cut.
onpasteExecuted when the content of an element is pasted.

Media-files Events Attributes

Media-files Events Attributes (媒体文件事件属性)

Media-files events occur in media elements, like video, image, audio. The attributes can be applied to any HTML element, but they are generally used within audio, embed, img, object and video elements. (媒体文件事件发生在媒体元素中,如视频、图像、音频。属性可以应用于任何HTML元素,但它们通常用于audio、embed、img、object和video元素。)

AttributeDescription
onabortExecuted when the loading of an audio/video is aborted.
New attribute in HTML5.
oncanplayExecuted when the file is ready to start playing (has buffered enough to start playing).
New attribute in HTML5.
oncanplaythroughExecuted when the file is ready to be played from start to end without stopping for buffering.
New attribute in HTML5.
oncuechangeExecuted when the duration of the media is changed.
New attribute in HTML5.
onemptiedExecuted when something happens and the file is unavailable (e.g., when the Internet connection is lost).
New attribute in HTML5.
onendedExecuted when a media file reached the end.
New attribute in HTML5.
onerrorExecuted when an error occurs when the file is being loaded.
New attribute in HTML5.
onloadeddataExecuted when media data is loaded.
New attribute in HTML5.
onloadedmetadataExecuted when metadata (size of media files, duration, etc. ) is loaded.
New attribute in HTML5.
onloadstartExecuted when the browser starts downloading media data.
New attribute in HTML5.
onpauseExecuted when the mediafile is paused. New attribute in HTML5.
onplayExecuted when the file is ready to start playing. New attribute in HTML5.
onplayingExecuted when the file starts playing.
New attribute in HTML5.
onprogressExecuted when the browser is in process of getting media data.
New attribute in HTML5.
onratechangeExecuted each time, when the playing mode is changed (e.g. user switches fast forward or slow motion mode).
New attribute in HTML5.
onseekedExecuted when the seeking attribute of the <audio> or <video> tags is set to false indicating that seeking has ended.
New attribute in HTML5.
onseekingExecuted when the seeking attribute of the <audio> or <video> tags is set to false indicating that seeking is active.
New attribute in HTML5.
onstalledExecuted when the browser cannot get media data for whatever reason.
New attribute in HTML5.
onsuspendExecuted when the browser has already started extracting media data, but the process was suspended before the data is completely loaded.
New attribute in HTML5.
ontimeupdateExecuted when the playing position is changed.
New attribute in HTML5.
onvolumechangeExecuted each time when the volume is changed (includes setting the volume to “mute”).
New attribute in HTML5.
onwaitingExecuted when media file is suspended, but is about to resume (e.g., when the file is paused for buffering).
New attribute in HTML5.

Other Events Attributes

Other Events Attributes (其他事件属性)

AttributeDescription
onerrorExecuted when an error occurs when downloading external file.
onshowExecuted when the <menu> is shown as a context menu.
New attribute in HTML5.
ontoggleExecuted when a user opens or closes the <details>.
New attribute in HTML5.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部