HTML5 参考手册 ———— 事件

窗口事件属性(Window Event Attributes)

 窗口触发该事件 (适用于 body 标签)

全局属性
名称 描述 备注 实例链接
onafterprint 在打印文档之后运行脚本 onafterprint 属性通常与 onbeforeprint 属性一起使用 实例链接
onbeforeprint 在用户设置页面打印,但在打印对话框出现前触发 目前只有 Internet Explorer 和 Firefox 浏览器支持 onbeforeprint 事件属性
onbeforeprint 属性通常与 onafterprint 属性一起使用
实例链接
onbeforeonload 在文档加载之前运行脚本 - -
onblur 当窗口失去焦点时运行脚本 - -
onerror 当错误发生时运行脚本 - -
onfocus 当窗口获得焦点时运行脚本 - -
onhashchange 当文档改变时运行脚本 - -
onload 在文档对象加载完成后触发 通常使用于 body 元素中,用于在页面完全载入后执行指定的脚本(包括图片,脚本,css文件等) 实例链接
onmessage 当触发消息时运行脚本 - -
onoffline 当文档离线时运行脚本 - -
ononline 当文档上线时运行脚本 - -
onpagehide 当窗口隐藏时运行脚本 - -
onpageshow 当窗口可见时运行脚本 - -
onredo 当文档执行再执行操作(redo)时运行脚本 - -
onresize 在调整窗口大小时触发 常用于调整窗口大小 实例链接
onstorage 当 Web Storage 区域更新时(存储空间中的数据发生变化时)运行脚本 - -
onundo 当文档执行撤销时运行脚本 - -
onunload 在用户关闭一个页面时触发 如果你重新载入页面,unload 事件将被触发( onload 事件) 实例链接

表单事件(Form Events)

 表单事件在HTML表单中触发 (适用于所有 HTML 元素, 但该HTML元素需在form表单内)。

全局属性
名称 描述 备注 实例链接
onblur 在元素失去焦点时触发 onblur 属性的相反属性onfocus 属性 实例链接
onchange 在元素值改变时触发 onchange 属性可适用于 input, textarea, 和 select 元素 实例链接
oncontextmenu 当触发上下文菜单时运行脚本 - -
onfocus 在元素获得焦点时触发 onfocus 属性不能使用于以下元素: base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
onformchange 当表单改变时运行脚本 - -
onforminput 当表单获得用户输入时运行脚本 - -
oninput 当元素获得用户输入时运行脚本 - -
oninvalid 当元素无效时运行脚本 - -
onselect 在选取元素文本后触发 可使用于以下元素: input type="file", input type="password", input type="text", keygen, 和 textarea 实例链接
onsubmit 在表单提交时触发 只适用于 form 元素 实例链接

键盘事件(Keyboard Events)

全局属性
名称 描述 备注 实例链接
onkeydown 在用户按下按键(在键盘上)时触发 onkeydown 属性不能用于以下元素: base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
onkeypress 当按下并松开按键时运行脚本 onkeypress 事件在所有浏览器中不能触发所有按键 实例链接
onkeyup 在用户松开按键(在键盘上)时触发 onkeyup 属性不能使用于以下元素:base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接

鼠标事件(Mouse Events)

 通过鼠标触发事件, 类似用户的行为。

全局属性
名称 描述 备注 实例链接
onclick 在单击鼠标时触发 不能应用于以下元素:base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
ondblclick 在元素上双击鼠标时触发 ondblclick 属性不能使用于以下函数: base, bdo, br, head, html, iframe, meta, param, script, style, 或title 实例链接
ondrag 当拖动元素时运行脚本 - -
ondragend 当拖动操作结束时运行脚本 - -
ondragenter 当元素被拖动至有效的拖放目标时运行脚本 - -
ondragstart 当拖动操作开始时运行脚本 - -
ondragleave 当元素离开有效拖放目标时运行脚本 - -
ondragover 当元素被拖动至有效拖放目标上方时运行脚本 - -
ondrop 当被拖动元素正在被拖放时运行脚本 - -
onmousedown 在按下鼠标按钮时触发 onmousedown 属性不能使用于以下元素: base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
onmousemove 当鼠标指针移动时运行脚本 onmousemove 属性不能使用于以下元素: base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
onmouseout 在鼠标指针移除元素时触发 onmouseout 属性不能使用于以下元素: base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
onmouseover 在鼠标指针移至元素之上时触发 onmouseout 属性不能使用于以下元素: base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
onmouseup 在用户松开鼠标按键时触发 onmouseout 属性不能使用于以下元素: base, bdo, br, head, html, iframe, meta, param, script, style, 或 title 实例链接
onmousewheel 当转动鼠标滚轮时运行脚本 - -
onscroll 当滚动元素的滚动条时运行脚本 - -

多媒体事件(Media Events)

 通过视频(videos),图像(images)或者音频(audio) 触发该事件,多应用于 HTML 媒体元素比如 audio, embed, img, object, 和 video。

全局属性
名称 描述 备注 实例链接
onabort 当发生中止事件时运行脚本 - -
oncanplay 当媒介能够开始播放但可能因缓冲而需要停止时运行脚本 - -
oncanplaythrough 当媒介能够无需因缓冲而停止即可播放至结尾时运行脚本 - -
ondurationchange 当媒介长度改变时运行脚本 - -
onemptied 当媒介资源元素突然为空时(网络错误、加载错误等)运行脚本 - -
onended 当媒介已抵达结尾时运行脚本 - -
onerror 当在元素加载期间发生错误时运行脚本 - -
onloadeddata 当加载媒介数据时运行脚本 - -
onloadedmetadata 当媒介元素的持续时间以及其他媒介数据已加载时运行脚本 - -
onloadstart 当浏览器开始加载媒介数据时运行脚本 - -
onpause 当媒介数据暂停时运行脚本 - -
onplay 当媒介数据将要开始播放时运行脚本 - -
onplaying 当媒介数据已开始播放时运行脚本 - -
onprogress 当浏览器正在取媒介数据时运行脚本 - -
onratechange 当媒介数据的播放速率改变时运行脚本 - -
onreadystatechange 当就绪状态(ready-state)改变时运行脚本 - -
onseeked 当媒介元素的定位属性 [1] 不再为真且定位已结束时运行脚本 - -
onseeking 当媒介元素的定位属性为真且定位已开始时运行脚本 - -
onstalled 当取回媒介数据过程中(延迟)存在错误时运行脚本 - -
onsuspend 当浏览器已在取媒介数据但在取回整个媒介文件之前停止时运行脚本 - -
ontimeupdate 当媒介改变其播放位置时运行脚本 - -
onvolumechange 当媒介改变音量亦或当音量被设置为静音时运行脚本 - -
onwaiting 当媒介已停止播放但打算继续播放时运行脚本 - -

其他事件

全局属性
名称 描述 备注 实例链接
onshow 当 menu 元素在上下文显示时触发 该事件仅在火狐浏览器中生效 实例链接
ontoggle 在用户打开或关闭 details 元素时触发 - 实例链接

猜你喜欢

转载自blog.csdn.net/qq_42957717/article/details/118705864