HTML 4.0 Event Attributes
HTML 4.0 Event Attributes
New to HTML 4.0 is the ability to let HTML events trigger actions in the browser, like starting a JavaScript when a user clicks on an HTML element. Below is a list of attributes that can be inserted into HTML tags to define event actions.
Window Events
Only valid in body and frameset elements.
Attribute | Value | Description |
---|---|---|
onload | script | Script to be run when a document loads |
onunload | script | Script to be run when a document unloads |
Form Element Events
Only valid in form elements.
Attribute | Value | Description |
---|---|---|
onchange | script | Script to be run when the element changes |
onsubmit | script | Script to be run when the form is submitted |
onreset | script | Script to be run when the form is reset |
onselect | script | Script to be run when the element is selected |
onblur | script | Script to be run when the element loses focus |
onfocus | script | Script to be run when the element gets focus |
Keyboard Events
Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.
Attribute | Value | Description |
---|---|---|
onkeydown | script | What to do when key is pressed |
onkeypress | script | What to do when key is pressed and released |
onkeyup | script | What to do when key is released |
Mouse Events
Not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, title elements.
Attribute | Value | Description |
---|---|---|
onclick | script | What to do on a mouse click |
ondblclick | script | What to do on a mouse double-click |
onmousedown | script | What to do when mouse button is pressed |
onmousemove | script | What to do when mouse pointer moves |
onmouseout | script | What to do when mouse pointer moves out of an element |
onmouseover | script | What to do when mouse pointer moves over an element |
onmouseup | script | What to do when mouse button is released |
Attribute definitions
- onload = script [CT]
- The onload event occurs when the user agent finishes loading a window or all frames within a FRAMESET. This attribute may be used with BODY and FRAMESET elements.
- onunload = script [CT]
- The onunload event occurs when the user agent removes a document from a window or frame. This attribute may be used with BODY and FRAMESET elements.
- onclick = script [CT]
- The onclick event occurs when the pointing device button is clicked over an element. This attribute may be used with most elements.
- ondblclick = script [CT]
- The ondblclick event occurs when the pointing device button is double clicked over an element. This attribute may be used with most elements.
- onmousedown = script [CT]
- The onmousedown event occurs when the pointing device button is pressed over an element. This attribute may be used with most elements.
- onmouseup = script [CT]
- The onmouseup event occurs when the pointing device button is released over an element. This attribute may be used with most elements.
- onmouseover = script [CT]
- The onmouseover event occurs when the pointing device is moved onto an element. This attribute may be used with most elements.
- onmousemove = script [CT]
- The onmousemove event occurs when the pointing device is moved while it is over an element. This attribute may be used with most elements.
- onmouseout = script [CT]
- The onmouseout event occurs when the pointing device is moved away from an element. This attribute may be used with most elements.
- onfocus = script [CT]
- The onfocus event occurs when an element receives focus either by the pointing device or by tabbing navigation. This attribute may be used with the following elements: A, AREA, LABEL, INPUT, SELECT, TEXTAREA, and BUTTON.
- onblur = script [CT]
- The onblur event occurs when an element loses focus either by the pointing device or by tabbing navigation. It may be used with the same elements as onfocus.
- onkeypress = script [CT]
- The onkeypress event occurs when a key is pressed and released over an element. This attribute may be used with most elements.
- onkeydown = script [CT]
- The onkeydown event occurs when a key is pressed down over an element. This attribute may be used with most elements.
- onkeyup = script [CT]
- The onkeyup event occurs when a key is released over an element. This attribute may be used with most elements.
- onsubmit = script [CT]
- The onsubmit event occurs when a form is submitted. It only applies to the FORM element.
- onreset = script [CT]
- The onreset event occurs when a form is reset. It only applies to the FORM element.
- onselect = script [CT]
- The onselect event occurs when a user selects some text in a text field. This attribute may be used with the INPUT and TEXTAREA elements.
- onchange = script [CT]
- The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus. This attribute applies to the following elements: INPUT, SELECT, and TEXTAREA.
REF:
http://www.w3.org/TR/REC-html40/interact/scripts.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY