HTML 5 事件屬性
- Previous Page
- Next Page
HTML 元素可擁有事件屬性,這些屬性在瀏覽器中觸發(fā)行為,比如當(dāng)用戶單擊一個 HTML 元素時啟動一段 JavaScript。下面列出的事件屬性,可以把它們插入 HTML 標(biāo)簽來定義事件行為。
如果需要學(xué)習(xí)更多有關(guān)使用這些事件進行編程的內(nèi)容,請學(xué)習(xí)我們的 JavaScript 教程 和 DHTML 教程。
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 事件時運行腳本。 | ? | 5 |
onbeforeonload | script? | 在元素加載前運行腳本。 | ? | 5 |
onblur | script? | 當(dāng)元素失去焦點時運行腳本。 | 4 | 5 |
onchange | script | 當(dāng)元素改變時運行腳本。 | 4 | 5 |
onclick | script? | 在鼠標(biāo)點擊時允許腳本。 | 4 | 5 |
oncontextmenu | script? | 當(dāng)菜單被觸發(fā)時運行腳本。 | ? | 5 |
ondblclick | script? | 當(dāng)鼠標(biāo)雙擊時運行腳本。 | 4 | 5 |
ondrag | script? | 只要腳本在被拖動就允許腳本。 | ? | 5 |
ondragend | script? | 在拖動操作結(jié)束時運行腳本。 | ? | 5 |
ondragenter | script? | 當(dāng)元素被拖動到一個合法的放置目標(biāo)時,執(zhí)行腳本。 | ? | 5 |
ondragleave | script? | 當(dāng)元素離開合法的放置目標(biāo)時。 | ? | 5 |
ondragover | script? | 只要元素正在合法的放置目標(biāo)上拖動時,就執(zhí)行腳本。 | ? | 5 |
ondragstart | script? | 在拖動操作開始時執(zhí)行腳本。 | ? | 5 |
ondrop | script? | 當(dāng)元素正在被拖動時執(zhí)行腳本。 | ? | 5 |
onerror | script? | 當(dāng)元素加載的過程中出現(xiàn)錯誤時執(zhí)行腳本。 | ? | 5 |
onfocus | script? | 當(dāng)元素獲得焦點時執(zhí)行腳本。 | 4 | 5 |
onkeydown | script? | 當(dāng)按鈕按下時執(zhí)行腳本。 | 4 | 5 |
onkeypress | script? | 當(dāng)按鍵被按下時執(zhí)行腳本。 | 4 | 5 |
onkeyup | script? | 當(dāng)按鈕松開時執(zhí)行腳本。 | 4 | 5 |
onload | script | 當(dāng)文檔加載時執(zhí)行腳本。 | 4 | 5 |
onmessage | script? | 當(dāng) message 事件觸發(fā)時執(zhí)行腳本。 | ? | 5 |
onmousedown | script? | 當(dāng)鼠標(biāo)按鈕按下時執(zhí)行腳本。 | 4 | 5 |
onmousemove | script? | 當(dāng)鼠標(biāo)指針移動時執(zhí)行腳本。 | 4 | 5 |
onmouseover | script | 當(dāng)鼠標(biāo)指針移動到一個元素上時執(zhí)行腳本。 | 4 | 5 |
onmouseout | script | 當(dāng)鼠標(biāo)指針移出元素時執(zhí)行腳本。 | 4 | 5 |
onmouseup | script? | 當(dāng)鼠標(biāo)按鈕松開時執(zhí)行腳本。 | 4 | 5 |
onmousewheel | script? | 當(dāng)鼠標(biāo)滾輪滾動時執(zhí)行腳本。 | ? | 5 |
onreset | script? | 當(dāng)表單重置時執(zhí)行腳本。不支持。 | 4 | ? |
onresize | script? | 當(dāng)元素調(diào)整大小時運行腳本。 | ? | 5 |
onscroll | script? | 當(dāng)元素滾動條被滾動時執(zhí)行腳本。 | ? | 5 |
onselect | script? | 當(dāng)元素被選中時執(zhí)行腳本。 | 4 | 5 |
onsubmit | script | 當(dāng)表單提交時運行腳本。 | 4 | 5 |
onunload | script | 當(dāng)文檔卸載時運行腳本。 | ? | 5 |
- Previous Page
- Next Page