下面的表格列出了可插入 HTML 5 元素中以定義事件行為的標(biāo)準(zhǔn)事件屬性。
window 對(duì)象觸發(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)窗口可見(jiàn)時(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í)(存儲(chǔ)空間中的數(shù)據(jù)發(fā)生變化時(shí)) |
| onunload | script | 當(dāng)用戶離開(kāi)文檔時(shí)運(yùn)行腳本 |
由 HTML 表單內(nèi)部的動(dòng)作觸發(fā)的事件。適用于所有 HTML 5 元素,不過(guò)最常用于表單元素中:
| 屬性 | 值 | 描述 |
|---|---|---|
| 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)按下并松開(kāi)按鍵時(shí)運(yùn)行腳本 |
| onkeyup | script | 當(dāng)松開(kāi)按鍵時(shí)運(yùn)行腳本 |
由鼠標(biāo)或相似的用戶動(dòng)作觸發(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)拖動(dòng)元素時(shí)運(yùn)行腳本 |
| ondragend | script | 當(dāng)拖動(dòng)操作結(jié)束時(shí)運(yùn)行腳本 |
| ondragenter | script | 當(dāng)元素被拖動(dòng)至有效的拖放目標(biāo)時(shí)運(yùn)行腳本 |
| ondragleave | script | 當(dāng)元素離開(kāi)有效拖放目標(biāo)時(shí)運(yùn)行腳本 |
| ondragover | script | 當(dāng)元素被拖動(dòng)至有效拖放目標(biāo)上方時(shí)運(yùn)行腳本 |
| ondragstart | script | 當(dāng)拖動(dòng)操作開(kāi)始時(shí)運(yùn)行腳本 |
| ondrop | script | 當(dāng)被拖動(dòng)元素正在被拖放時(shí)運(yùn)行腳本 |
| onmousedown | script | 當(dāng)按下鼠標(biāo)按鈕時(shí)運(yùn)行腳本 |
| onmousemove | script | 當(dāng)鼠標(biāo)指針移動(dòng)時(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)松開(kāi)鼠標(biāo)按鈕時(shí)運(yùn)行腳本 |
| onmousewheel | script | 當(dāng)轉(zhuǎn)動(dòng)鼠標(biāo)滾輪時(shí)運(yùn)行腳本 |
| onscroll | script | 當(dāng)滾動(dòng)元素滾動(dòng)元素的滾動(dòng)條時(shí)運(yùn)行腳本 |
由視頻、圖像以及音頻等媒介觸發(fā)的事件。適用于所有 HTML 5 元素,不過(guò)在媒介元素(諸如 audio、embed、img、object 以及 video)中最常用:
| 屬性 | 值 | 描述 |
|---|---|---|
| onabort | script | 當(dāng)發(fā)生中指事件時(shí)運(yùn)行腳本 |
| oncanplay | script | 當(dāng)媒介能夠開(kāi)始播放但可能因緩沖而需要停止時(shí)運(yùn)行腳本 |
| oncanplaythrough | script | 當(dāng)媒介能夠無(wú)需因緩沖而停止即可播放至結(jié)尾時(shí)運(yùn)行腳本 |
| ondurationchange | script | 當(dāng)媒介長(zhǎ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)瀏覽器開(kāi)始加載媒介數(shù)據(jù)時(shí)運(yùn)行腳本 |
| onpause | script | 當(dāng)媒介數(shù)據(jù)暫停時(shí)運(yùn)行腳本 |
| onplay | script | 當(dāng)媒介數(shù)據(jù)將要開(kāi)始播放時(shí)運(yùn)行腳本 |
| onplaying | script | 當(dāng)媒介數(shù)據(jù)已開(kāi)始播放時(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)媒介元素的定位屬性為真且定位已開(kāi)始時(shí)運(yùn)行腳本 |
| onstalled | script | 當(dāng)取回媒介數(shù)據(jù)過(guò)程中(延遲)存在錯(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事件方法全部匯總就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選