首頁  >  文章  >  web前端  >  HTML 事件

HTML 事件

WBOY
WBOY原創
2024-09-04 16:14:20843瀏覽

在使用 HTML 腳本(超文本標記語言)建立的網頁或網站中,使用者和 Web 工具本身執行的每個操作稱為 HTML 事件。每個事件的描述包含六種類型的屬性:視窗事件屬性、表單事件屬性、鍵盤事件屬性、滑鼠事件屬性、媒體事件屬性和剪貼簿事件屬性。每個事件屬性都將具有特定的專用屬性,用於取得 HTML 事件的詳細資訊。

不同類型的 HTML 事件

HTML5 中有許多可用的事件屬性,主要分為 6 種不同類型。這些屬性使用 JavaScript 語言來工作。

HTML 事件

  •  Windows 事件屬性: 這是為 windows 物件的操作提供的。它適用於 body 標籤。
  •  表單事件屬性: 如果使用者在表單中執行某些操作(例如輸入資料、取消、提交),則這些事件屬性將起作用。
  •  鍵盤事件屬性: 此鍵盤事件屬性用於鍵盤操作和使用者互動。
  •  滑鼠事件屬性: 用於移動、點擊、滾輪等滑鼠操作的滑鼠事件屬性。
  •  剪貼簿事件屬性: 此事件屬性用於剪貼簿操作:例如、剪下、複製、害蟲。
  •  媒體事件屬性: 此事件屬性適用於影片等媒體檔案。

事件屬性說明

這裡是一些事件屬性的解釋,以下詳細給出:

1. Windows 事件屬性

Attribute

Description

onafterprint This script act, though, after the document printed.
onbeforeprint This script act, though, before a document printed.
onbeforeunload Whereas before the unloaded document, this Script works.
onerror  In the document occurs the Error then this event executed.
onhashchange  The anchor part of URL change in the document that time event executed.
onload When the first Web page is loaded completely, then this event executed.
onmessage In the document, the message that occurred at that time event executed.
onoffline If the network connection is unavailable and the browser says offline, then the event executed.
ononline When the network available in the browser, then the event executed.
onpagehide This script act; if the user not working on a current webpage, a then-current page can be hidden.
onpageshow This script act at that time the current webpage is load.
onpopstate This script automatically works on the browser for a history state change.
onresize This script act when the browser of the window changes the size.
onstorage When users web storage updated, then the event executed.
onunload The user’s current web page is not loaded or the window is closed, then the event is executed.
屬性

描述

onafterprint 不過,該腳本在文件列印後起作用。 onbeforeprint 不過,該腳本在列印文件之前起作用。 卸載前 在卸載文件之前,此腳本有效。 錯誤  文件中發生錯誤,然後執行此事件。 onhashchange  事件執行時文件中 URL 的錨點部分發生變化。 載入 當第一個網頁載入完成時,執行此事件。 onmessage 在文件中,執行當時發生的事件的訊息。 線上離線 如果網路連線不可用且瀏覽器顯示離線,則執行該事件。 線上 當瀏覽器中網路可用時,則執行該事件。 頁隱藏 這個腳本行為;如果使用者不在目前網頁上工作,則可以隱藏目前頁面。 onpageshow 此腳本在目前網頁載入時起作用。 onpopstate 此腳本會自動在瀏覽器上執行以變更歷史狀態。 調整大小 此腳本在視窗的瀏覽器改變大小時起作用。 儲存 當用戶網路儲存更新時,則執行該事件。 卸載 使用者目前網頁未載入或視窗關閉,則執行該事件。 表>

2.表單事件屬性

Attribute Description
onblur Some form validation object loos the focus, then event fired.
onchange The value change in the form, then event fired.
onfocus In the form , ,
oninput The user gives input of value in the form then this event fired.
oninvalid The event works on when the element does not satisfy its predefined constraints.
onreset User reset the form information, then event fired.
onsearch Users search the required field, then event fired.
onselect The user selects the text or text area in form, then event fired.
onsubmit The user submits the form at the end then the event fired.

3.鍵盤事件屬性

Attribute    Description
onkeydown Using a keyboard, the user press the key down at that point event works
onkeypress Using the keyboard, users press the key and display characters at that point event works.
onkeyup After the press, the key user releases the key then the event works.

4.滑鼠事件屬性

   Attribute Description
onclick The user clicks the mouse on the button then an event occurred.
ondblclick Users double click the mouse then the event occurred.
onmousedown The user presses the mouse button on the element then the event occurred.
onmousemove The user moves the mouse pointer over the element then the event occurred.
onmouseout The user moves the mouse outside of the element then the event occurred.
onmouseover  The user moves the mouse over the element then the event occurred.
onmouseup The user released the mouse button then the event occurred.
onmousewheel Using the mouse wheel user rolls the up and down on element then the event occurred.
onwheel Using a mouse wheel user roll them up and down then the event occurred.

5.剪貼簿事件屬性

 Attribute Description
oncopy Using mouse users to copy the content, then the event occurred.
oncut Using a mouse, users cut the content then the event occurred.
onpaste Using a mouse user, paste the content, then an event occurred.

6.媒體事件屬性

Attribute Description
onabort When media files aborted for download and play again, then an event occurs.
oncanplay When any media file ready for play, then this trigger is fired.
oncanplaythrough Media file ready to play without buffering and loading.
oncuechange Element changes the cue of then event fired.
ondurationchange The Media file changes the length of time then the trigger is fired.
onemptied If the Media file unavailable and come fatal error, then the trigger is fired.
onended The Media file comes on endpoint then the trigger is fired.
onerror When an error occurred to get the media file, the trigger is fired
onloadeddata The Media file loads the data then the trigger is fired.
onloadedmetadata The Media file loads the metadata then the trigger is fired.
onloadstart The Media file starts to load then the trigger is fired.
onpause The Media file paused to play again then the trigger is fired.
onplay Media file ready to play, then trigger is fired.
onplaying The Media file starts to play when the trigger is fired.
onprogress This script act when the browser is working on connecting with the media data.
onratechange If the videos playback speed is changed, then the trigger is fired.
onseeked Users completed moving; otherwise, skip the new position of video. this attribute set as false.
onseeking The user wants to move; otherwise, skip the new position of the video. this attribute set as true.
onstalled When the browser suddenly stops to the connection of data, then the event works.
onsuspend When the web Browser on purpose does not get media data, then events work.
ontimeupdate When a user changes the video play position like forward and backward.
onvolumechange To change media volume low to high.
onwaiting If the data load the information, current video stop with buffering then event works.

結論

Html 事件是在 Web 瀏覽器和使用者之間採取操作和互動的簡單方法。使用者可以毫不費力地獲得每個動作的反應。例如,剪貼簿的剪下和複製、滑鼠的移動和點擊、表單的按鈕。事件使網路應用程式變得即時並打造智慧工作系統。

以上是HTML 事件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:HTML 指令下一篇:HTML 指令