HTML 元素可擁有事件屬性,這些屬性在瀏覽器中觸發(fā)行為,比如當(dāng)用戶(hù)單擊一個(gè) HTML 元素時(shí)啟動(dòng)一段 JavaScript。下面列出的事件屬性,可以把它們插入 HTML 標(biāo)簽來(lái)定義事件行為。 HTML 4.01 與 HTML 5 之間的差異 HTML 5 中的新事件:onabort, onbeforeunload, onconte
HTML 元素可擁有事件屬性,這些屬性在瀏覽器中觸發(fā)行為,比如當(dāng)用戶(hù)單擊一個(gè) HTML 元素時(shí)啟動(dòng)一段 JavaScript。下面列出的事件屬性,可以把它們插入 HTML 標(biāo)簽來(lái)定義事件行為。
HTML 4.01 與 HTML 5 之間的差異
HTML 5 中的新事件:onabort, onbeforeunload, oncontextmenu, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onerror, onmessage, onmousewheel, onresize, onscroll, onunload。
不再支持的 HTML 4.01 屬性:onreset。
屬性
屬性 | 值 | 描述 | 4 | 5 |
---|---|---|---|---|
onabort | script | 發(fā)生 abort 事件時(shí)運(yùn)行腳本。 | 5 | |
onbeforeonload | script | 在元素加載前運(yùn)行腳本。 | 5 | |
onblur | script | 當(dāng)元素失去焦點(diǎn)時(shí)運(yùn)行腳本。 | 4 | 5 |
onchange | script | 當(dāng)元素改變時(shí)運(yùn)行腳本。 | 4 | 5 |
onclick | script | 在鼠標(biāo)點(diǎn)擊時(shí)允許腳本。 | 4 | 5 |
oncontextmenu | script | 當(dāng)菜單被觸發(fā)時(shí)運(yùn)行腳本。 | 5 | |
ondblclick | script | 當(dāng)鼠標(biāo)雙擊時(shí)運(yùn)行腳本。 | 4 | 5 |
ondrag | script | 只要腳本在被拖動(dòng)就允許腳本。 | 5 | |
ondragend | script | 在拖動(dòng)操作結(jié)束時(shí)運(yùn)行腳本。 | 5 | |
ondragenter | script | 當(dāng)元素被拖動(dòng)到一個(gè)合法的放置目標(biāo)時(shí),執(zhí)行腳本。 | 5 | |
ondragleave | script | 當(dāng)元素離開(kāi)合法的放置目標(biāo)時(shí)。 | 5 | |
ondragover | script | 只要元素正在合法的放置目標(biāo)上拖動(dòng)時(shí),就執(zhí)行腳本。 | 5 | |
ondragstart | script | 在拖動(dòng)操作開(kāi)始時(shí)執(zhí)行腳本。 | 5 | |
ondrop | script | 當(dāng)元素正在被拖動(dòng)時(shí)執(zhí)行腳本。 | 5 | |
onerror | script | 當(dāng)元素加載的過(guò)程中出現(xiàn)錯(cuò)誤時(shí)執(zhí)行腳本。 | 5 | |
onfocus | script | 當(dāng)元素獲得焦點(diǎn)時(shí)執(zhí)行腳本。 | 4 | 5 |
onkeydown | script | 當(dāng)按鈕按下時(shí)執(zhí)行腳本。 | 4 | 5 |
onkeypress | script | 當(dāng)按鍵被按下時(shí)執(zhí)行腳本。 | 4 | 5 |
onkeyup | script | 當(dāng)按鈕松開(kāi)時(shí)執(zhí)行腳本。 | 4 | 5 |
onload | script | 當(dāng)文檔加載時(shí)執(zhí)行腳本。 | 4 | 5 |
onmessage | script | 當(dāng) message 事件觸發(fā)時(shí)執(zhí)行腳本。 | 5 | |
onmousedown | script | 當(dāng)鼠標(biāo)按鈕按下時(shí)執(zhí)行腳本。 | 4 | 5 |
onmousemove | script | 當(dāng)鼠標(biāo)指針移動(dòng)時(shí)執(zhí)行腳本。 | 4 | 5 |
onmouseover | script | 當(dāng)鼠標(biāo)指針移動(dòng)到一個(gè)元素上時(shí)執(zhí)行腳本。 | 4 | 5 |
onmouseout | script | 當(dāng)鼠標(biāo)指針移出元素時(shí)執(zhí)行腳本。 | 4 | 5 |
onmouseup | script | 當(dāng)鼠標(biāo)按鈕松開(kāi)時(shí)執(zhí)行腳本。 | 4 | 5 |
onmousewheel | script | 當(dāng)鼠標(biāo)滾輪滾動(dòng)時(shí)執(zhí)行腳本。 | 5 | |
onreset | script | 當(dāng)表單重置時(shí)執(zhí)行腳本。不支持。 | 4 | |
onresize | script | 當(dāng)元素調(diào)整大小時(shí)運(yùn)行腳本。 | 5 | |
onscroll | script | 當(dāng)元素滾動(dòng)條被滾動(dòng)時(shí)執(zhí)行腳本。 | 5 | |
onselect | script | 當(dāng)元素被選中時(shí)執(zhí)行腳本。 | 4 | 5 |
onsubmit | script | 當(dāng)表單提交時(shí)運(yùn)行腳本。 | 4 | 5 |
onunload | script | 當(dāng)文檔卸載時(shí)運(yùn)行腳本。 | 5 |