XHTML 事件屬性
HTML 4.0 的新特性之一是使 HTML 事件觸發(fā)瀏覽器中的行為,比方說當(dāng)用戶點(diǎn)擊一個(gè) HTML 元素時(shí)啟動(dòng)一段 JavaScript 。以下就是可被插入 HTML 標(biāo)簽以定義事件行為的一系列屬性。
假如你希望學(xué)習(xí)如何使用這些事件進(jìn)行編程,那么你應(yīng)該學(xué)習(xí)我們的 JavaScript 教程 和 DHTML 教程。
窗口事件 (Window Events)
僅在 body 和 frameset 元素中有效。
| 屬性 | 值 | 描述 |
|---|---|---|
| onload | 腳本 | 當(dāng)文檔被載入時(shí)執(zhí)行腳本 |
| onunload | 腳本 | 當(dāng)文檔被卸下時(shí)執(zhí)行腳本 |
表單元素事件 (Form Element Events)
僅在表單元素中有效。
| 屬性 | 值 | 描述 |
|---|---|---|
| onchange | 腳本 | 當(dāng)元素改變時(shí)執(zhí)行腳本 |
| onsubmit | 腳本 | 當(dāng)表單被提交時(shí)執(zhí)行腳本 |
| onreset | 腳本 | 當(dāng)表單被重置時(shí)執(zhí)行腳本 |
| onselect | 腳本 | 當(dāng)元素被選取時(shí)執(zhí)行腳本 |
| onblur | 腳本 | 當(dāng)元素失去焦點(diǎn)時(shí)執(zhí)行腳本 |
| onfocus | 腳本 | 當(dāng)元素獲得焦點(diǎn)時(shí)執(zhí)行腳本 |
鍵盤事件 (Keyboard Events)
在下列元素中無效:base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, 以及 title 元素。
| 屬性 | 值 | 描述 |
|---|---|---|
| onkeydown | 腳本 | 當(dāng)鍵盤被按下時(shí)執(zhí)行腳本 |
| onkeypress | 腳本 | 當(dāng)鍵盤被按下后又松開時(shí)執(zhí)行腳本 |
| onkeyup | 腳本 | 當(dāng)鍵盤被松開時(shí)執(zhí)行腳本 |
鼠標(biāo)事件 (Mouse Events)
在下列元素中無效:base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, title 元素。
| 屬性 | 值 | 描述 |
|---|---|---|
| onclick | 腳本 | 當(dāng)鼠標(biāo)被單擊時(shí)執(zhí)行腳本 |
| ondblclick | 腳本 | 當(dāng)鼠標(biāo)被雙擊時(shí)執(zhí)行腳本 |
| onmousedown | 腳本 | 當(dāng)鼠標(biāo)按鈕被按下時(shí)執(zhí)行腳本 |
| onmousemove | 腳本 | 當(dāng)鼠標(biāo)指針移動(dòng)時(shí)執(zhí)行腳本 |
| onmouseout | 腳本 | 當(dāng)鼠標(biāo)指針移出某元素時(shí)執(zhí)行腳本 |
| onmouseover | 腳本 | 當(dāng)鼠標(biāo)指針懸停于某元素之上時(shí)執(zhí)行腳本 |
| onmouseup | 腳本 | 當(dāng)鼠標(biāo)按鈕被松開時(shí)執(zhí)行腳本 |