您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關(guān)HTML5事件有哪些,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
下面的表格列出了可插入 HTML 5 元素中以定義事件行為的標(biāo)準(zhǔn)事件屬性。
Window 事件屬性 - Window Event Attributes
表單事件 - Form Events
鍵盤事件 - Keybord Events
鼠標(biāo)事件 - Mouse Events
媒介事件 - Media Events
Window 事件屬性
window 對象觸發(fā)的事件。適用于 <body> 標(biāo)簽:
屬性 | 值 | 描述 |
---|---|---|
onafterprint | script | 在打印文檔之后運(yùn)行腳本 |
onbeforeprint | script | 在文檔打印之前運(yùn)行腳本 |
onbeforeonload | script | 在文檔加載之前運(yùn)行腳本 |
onblur | script | 當(dāng)窗口失去焦點(diǎn)時(shí)運(yùn)行腳本 |
onerror | script | 當(dāng)錯(cuò)誤發(fā)生時(shí)運(yùn)行腳本 |
onfocus | script | 當(dāng)窗口獲得焦點(diǎn)時(shí)運(yùn)行腳本 |
onhaschange | script | 當(dāng)文檔改變時(shí)運(yùn)行腳本 |
onload | script | 當(dāng)文檔加載時(shí)運(yùn)行腳本 |
onmessage | script | 當(dāng)觸發(fā)消息時(shí)運(yùn)行腳本 |
onoffline | script | 當(dāng)文檔離線時(shí)運(yùn)行腳本 |
ononline | script | 當(dāng)文檔上線時(shí)運(yùn)行腳本 |
onpagehide | script | 當(dāng)窗口隱藏時(shí)運(yùn)行腳本 |
onpageshow | script | 當(dāng)窗口可見時(shí)運(yùn)行腳本 |
onpopstate | script | 當(dāng)窗口歷史記錄改變時(shí)運(yùn)行腳本 |
onredo | script | 當(dāng)文檔執(zhí)行再執(zhí)行操作(redo)時(shí)運(yùn)行腳本 |
onresize | script | 當(dāng)調(diào)整窗口大小時(shí)運(yùn)行腳本 |
onstorage | script | 當(dāng)文檔加載加載時(shí)運(yùn)行腳本 |
onundo | script | 當(dāng) Web Storage 區(qū)域更新時(shí)(存儲空間中的數(shù)據(jù)發(fā)生變化時(shí)) |
onunload | script | 當(dāng)用戶離開文檔時(shí)運(yùn)行腳本 |
表單事件
由 HTML 表單內(nèi)部的動作觸發(fā)的事件。適用于所有 HTML 5 元素,不過最常用于表單元素中:
屬性 | 值 | 描述 |
---|---|---|
onblur | script | 當(dāng)元素失去焦點(diǎn)時(shí)運(yùn)行腳本 |
onchange | script | 當(dāng)元素改變時(shí)運(yùn)行腳本 |
oncontextmenu | script | 當(dāng)觸發(fā)上下文菜單時(shí)運(yùn)行腳本 |
onfocus | script | 當(dāng)元素獲得焦點(diǎn)時(shí)運(yùn)行腳本 |
onformchange | script | 當(dāng)表單改變時(shí)運(yùn)行腳本 |
onforminput | script | 當(dāng)表單獲得用戶輸入時(shí)運(yùn)行腳本 |
oninput | script | 當(dāng)元素獲得用戶輸入時(shí)運(yùn)行腳本 |
oninvalid | script | 當(dāng)元素?zé)o效時(shí)運(yùn)行腳本 |
onreset | script | 當(dāng)表單重置時(shí)運(yùn)行腳本。HTML 5 不支持。 |
onselect | script | 當(dāng)選取元素時(shí)運(yùn)行腳本 |
onsubmit | script | 當(dāng)提交表單時(shí)運(yùn)行腳本 |
鍵盤事件
由鍵盤觸發(fā)的事件。適用于所有 HTML 5 元素:
屬性 | 值 | 描述 |
---|---|---|
onkeydown | script | 當(dāng)按下按鍵時(shí)運(yùn)行腳本 |
onkeypress | script | 當(dāng)按下并松開按鍵時(shí)運(yùn)行腳本 |
onkeyup | script | 當(dāng)松開按鍵時(shí)運(yùn)行腳本 |
鼠標(biāo)事件
由鼠標(biāo)或相似的用戶動作觸發(fā)的事件。適用于所有 HTML 5 元素:
屬性 | 值 | 描述 |
---|---|---|
onclick | script | 當(dāng)單擊鼠標(biāo)時(shí)運(yùn)行腳本 |
ondblclick | script | 當(dāng)雙擊鼠標(biāo)時(shí)運(yùn)行腳本 |
ondrag | script | 當(dāng)拖動元素時(shí)運(yùn)行腳本 |
ondragend | script | 當(dāng)拖動操作結(jié)束時(shí)運(yùn)行腳本 |
ondragenter | script | 當(dāng)元素被拖動至有效的拖放目標(biāo)時(shí)運(yùn)行腳本 |
ondragleave | script | 當(dāng)元素離開有效拖放目標(biāo)時(shí)運(yùn)行腳本 |
ondragover | script | 當(dāng)元素被拖動至有效拖放目標(biāo)上方時(shí)運(yùn)行腳本 |
ondragstart | script | 當(dāng)拖動操作開始時(shí)運(yùn)行腳本 |
ondrop | script | 當(dāng)被拖動元素正在被拖放時(shí)運(yùn)行腳本 |
onmousedown | script | 當(dāng)按下鼠標(biāo)按鈕時(shí)運(yùn)行腳本 |
onmousemove | script | 當(dāng)鼠標(biāo)指針移動時(shí)運(yùn)行腳本 |
onmouseout | script | 當(dāng)鼠標(biāo)指針移出元素時(shí)運(yùn)行腳本 |
onmouseover | script | 當(dāng)鼠標(biāo)指針移至元素之上時(shí)運(yùn)行腳本 |
onmouseup | script | 當(dāng)松開鼠標(biāo)按鈕時(shí)運(yùn)行腳本 |
onmousewheel | script | 當(dāng)轉(zhuǎn)動鼠標(biāo)滾輪時(shí)運(yùn)行腳本 |
onscroll | script | 當(dāng)滾動元素滾動元素的滾動條時(shí)運(yùn)行腳本 |
媒介事件
由視頻、圖像以及音頻等媒介觸發(fā)的事件。適用于所有 HTML 5 元素,不過在媒介元素(諸如 audio、embed、img、object 以及 video)中最常用:
屬性 | 值 | 描述 |
---|---|---|
onabort | script | 當(dāng)發(fā)生中指事件時(shí)運(yùn)行腳本 |
oncanplay | script | 當(dāng)媒介能夠開始播放但可能因緩沖而需要停止時(shí)運(yùn)行腳本 |
oncanplaythrough | script | 當(dāng)媒介能夠無需因緩沖而停止即可播放至結(jié)尾時(shí)運(yùn)行腳本 |
ondurationchange | script | 當(dāng)媒介長度改變時(shí)運(yùn)行腳本 |
onemptied | script | 當(dāng)媒介資源元素突然為空時(shí)(網(wǎng)絡(luò)錯(cuò)誤、加載錯(cuò)誤等)運(yùn)行腳本 |
onended | script | 當(dāng)媒介已抵達(dá)結(jié)尾時(shí)運(yùn)行腳本 |
onerror | script | 當(dāng)在元素加載期間發(fā)生錯(cuò)誤時(shí)運(yùn)行腳本 |
onloadeddata | script | 當(dāng)加載媒介數(shù)據(jù)時(shí)運(yùn)行腳本 |
onloadedmetadata | script | 當(dāng)媒介元素的持續(xù)時(shí)間以及其他媒介數(shù)據(jù)已加載時(shí)運(yùn)行腳本 |
onloadstart | script | 當(dāng)瀏覽器開始加載媒介數(shù)據(jù)時(shí)運(yùn)行腳本 |
onpause | script | 當(dāng)媒介數(shù)據(jù)暫停時(shí)運(yùn)行腳本 |
onplay | script | 當(dāng)媒介數(shù)據(jù)將要開始播放時(shí)運(yùn)行腳本 |
onplaying | script | 當(dāng)媒介數(shù)據(jù)已開始播放時(shí)運(yùn)行腳本 |
onprogress | script | 當(dāng)瀏覽器正在取媒介數(shù)據(jù)時(shí)運(yùn)行腳本 |
onratechange | script | 當(dāng)媒介數(shù)據(jù)的播放速率改變時(shí)運(yùn)行腳本 |
onreadystatechange | script | 當(dāng)就緒狀態(tài)(ready-state)改變時(shí)運(yùn)行腳本 |
onseeked | script | 當(dāng)媒介元素的定位屬性[1]不再為真且定位已結(jié)束時(shí)運(yùn)行腳本 |
onseeking | script | 當(dāng)媒介元素的定位屬性為真且定位已開始時(shí)運(yùn)行腳本 |
onstalled | script | 當(dāng)取回媒介數(shù)據(jù)過程中(延遲)存在錯(cuò)誤時(shí)運(yùn)行腳本 |
onsuspend | script | 當(dāng)瀏覽器已在取媒介數(shù)據(jù)但在取回整個(gè)媒介文件之前停止時(shí)運(yùn)行腳本 |
ontimeupdate | script | 當(dāng)媒介改變其播放位置時(shí)運(yùn)行腳本 |
onvolumechange | script | 當(dāng)媒介改變音量亦或當(dāng)音量被設(shè)置為靜音時(shí)運(yùn)行腳本 |
onwaiting | script | 當(dāng)媒介已停止播放但打算繼續(xù)播放時(shí)運(yùn)行腳本 |
[1]:定位屬性的英文譯文是:seeking attribute。
以上就是HTML5事件有哪些,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。