Html 简明教程

HTML - Events Reference

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

When users visit your website, they do things like click various links, bring mouse over text and images etc. These are examples of what we call events in JavaScript and VBScript terminologies.

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

We can write our event handlers using JavaScript or VBScript and can specify some actions to be taken against these events. Though these are the events but they will be specified as attributes for the HTML tags.

HTML 4.01 规范定义了 19 个事件,但后来的 HTML-5 添加了很多其他事件,我们已将它们列在下面 −

The HTML 4.01 specification had defined 19 events but later HTML-5 has added many other events which we have listed down here −

Window Events Attributes

以下是列出的窗口事件属性:

Following are the window events attributes that are listed below −

Sr.No

Events & Description

1

onafterprint Triggers after a document is printed

2

onbeforeprint Triggers before a document is printed

3

onbeforeunload Triggers before a document loads

4

onerror Triggers when an error occurs

5

onhashchange Triggers when a document has changed

6

onload Triggers when a document loads

7

onoffline Triggers when a document goes offline

8

ononline Triggers when a document comes online

9

onpagehide Triggers when a window is hidden

10

onpageshow Triggers when a window becomes visible

11

onresize Triggers when a window is resized

12

onunload Triggers when a user leaves the document

Form Events

以下是下面列出的表单事件属性:

Following are the Form events attributes that are listed below −

Sr.No

Events & Description

1

onblur Triggers when a window loses focus

2

onchange Triggers when an element changes

3

oncontextmenu Triggers when a context menu is triggered

4

onfocus Triggers when a window gets focus

5

oninput Triggers when an element gets user input

6

oninvalid Triggers when an element is invalid

7

onreset Triggers when a form is reset

8

onsearch The HTML onsearch event allows to run specific JavaScript code when a user conducts a search action within a searchable input field.

9

onselect Triggers when an element is selected

10

onsubmit Triggers when a form is submitted

Keyboard Events

以下 HTML 鍵盤事件如下所列 −

Following are the HTML Keyboard Events that are listed below −

Sr.No

Events & Description

1

onkeydown Triggers when a key is pressed

2

onkeyup Triggers when a key is released

Mouse Events

以下滑鼠事件屬性如下所列 −

Following are the Mouse events attributes that are listed below −

Sr.No

Events & Description

1

onclick Triggers on a mouse click

2

ondblclick Triggers on a mouse double-click

3

onmousedown Triggers when a mouse button is pressed

4

onmousemove Triggers when the mouse pointer moves

5

onmouseout Triggers when the mouse pointer moves out of an element

6

onmouseover Triggers when the mouse pointer moves over an element

7

onmouseup Triggers when a mouse button is released

8

onwheel When the mouse wheel is over an element, the HTML onwheel event takes place.

Drag Events

以下 HTML 拖曳事件如下所列 −

Following are the HTML drag events that are listed below −

Sr.No

Events & Description

1

ondrag Triggers when an element is dragged

2

ondragend Triggers at the end of a drag operation

3

ondragenter Triggers when an element has been dragged to a valid drop target

4

ondragleave Triggers when an element leaves a valid drop target

5

ondragover Triggers when an element is being dragged over a valid drop target

6

ondragstart Triggers at the start of a drag operation

7

ondrop Triggers when a dragged element is being dropped

8

onscroll Triggers when an element’s scrollbar is being scrolled

Clipboard Events

让我们看下下面列出的剪贴板事件 −

Let’s look into the following clipboard events that are listed below −

Sr.No

Events & Description

1

oncopy Triggers when an element is copied by the user

2

oncut Triggers when an element is removed (cut) by the user

3

onpaste Triggers when an element is being pasted into an input field.

Media Events

下面是媒体事件属性列表 −

Following are the Media events attributes that are listed below −

Sr.No

Events & Description

1

ondurationchange Triggers when the length of a media is changed

2

onended Triggers when a media has reached the end

3

onerror Triggers when an error occurs

4

onloadeddata Triggers when media data is loaded

5

onloadedmetadata Triggers when the duration and other media data of a media element is loaded

6

onloadstart Triggers when the browser starts loading the media data

7

onpause Triggers when media data is paused

8

onplay Triggers when media data is going to start playing

9

onplaying Triggers when media data has started playing

10

onprogress Triggers when the browser is fetching the media data

11

onratechange Triggers when the playing rate of media data has changed

12

onseeked Triggers when the seeking attribute of a media element is no longer true, and the seeking has ended

13

onseeking Triggers when the seeking attribute of a media element is true, and the seeking has begun

14

onstalled Triggers when there is an error in fetching media data

15

onsuspend Triggers when the browser has been fetching media data, but stopped before the entire media file was fetched

16

ontimeupdate Triggers when media changes its playing position

17

onvolumechange Triggers when a media changes the volume, also when volume is set to "mute"

18

onwaiting Triggers when media has stopped playing, but is expected to resume

Misc Events

按照下面列出的 misc 事件:

Following the misc event listed below −

Sr.No

Event & Description

1

ontoggle In general, the toggle means it toggles between hide() and show() for the selected element.