📜  HTML-事件参考

📅  最后修改于: 2020-12-16 06:03:29             🧑  作者: Mango


当用户访问您的网站时,他们会执行诸如单击文本和图像以及给定链接,将鼠标悬停在事物上等操作。这些都是JavaScript称为事件的示例。

我们可以用Javascript或vbscript编写事件处理程序,并可以将这些事件处理程序指定为事件标记属性的值。 HTML 4.01规范定义了19个事件属性,如下所示-

和级事件

当文档级发生任何事件时,只有两个属性可用于触发任何javascript或vbscript代码。

Attribute Value Description
onload script Script runs when a HTML document loads
onunload script Script runs when a HTML document unloads

–这里的脚本是指任何VBScript或JavaScript函数或一段代码。

级别事件

当表单级发生任何事件时,可以使用以下六个属性来触发任何javascript或vbscript代码。

Attribute Value Description
onchange script Script runs when the element changes
onsubmit script Script runs when the form is submitted
onreset script Script runs when the form is reset
onselect script Script runs when the element is selected
onblur script Script runs when the element loses focus
onfocus script Script runs when the element gets focus

键盘事件

键盘产生以下三个事件。这些事件在base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style和title元素中无效。

Attribute Value Description
onkeydown script Script runs when key is pressed
onkeypress script Script runs when key is pressed and released
onkeyup script Script runs when key is released

其他活动

当鼠标接触任何HTML标记时,鼠标还会生成以下其他7个事件。这些事件在base,bdo,br,frame,frameset,head,html,iframe,meta,param,script,style,title元素中无效。

Attribute Value Description
onclick script Script runs when a mouse click
ondblclick script Script runs when a mouse double-click
onmousedown script Script runs when mouse button is pressed
onmousemove script Script runs when mouse pointer moves
onmouseout script Script runs when mouse pointer moves out of an element
onmouseover script Script runs when mouse pointer moves over an element
onmouseup script Script runs when mouse button is released