📜  JavaScript事件处理

📅  最后修改于: 2020-10-26 02:27:53             🧑  作者: Mango

JavaScript事件

对象状态的变化称为事件。在html中,有各种事件表示某些活动是由用户或浏览器执行的。当HTML中包含JavaScript代码时,js对这些事件做出反应并允许执行。对事件做出反应的过程称为事件处理。因此,js通过事件处理程序处理HTML事件。

例如,当用户单击浏览器时,添加js代码,这将执行要在事件上执行的任务。

一些HTML事件及其事件处理程序为:

鼠标事件:

Event Performed Event Handler Description
click onclick When mouse click on an element
mouseover onmouseover When the cursor of the mouse comes over the element
mouseout onmouseout When the cursor of the mouse leaves an element
mousedown onmousedown When the mouse button is pressed over the element
mouseup onmouseup When the mouse button is released over the element
mousemove onmousemove When the mouse movement takes place.

键盘事件:

Event Performed Event Handler Description
Keydown & Keyup onkeydown & onkeyup When the user press and then release the key

表单事件:

Event Performed Event Handler Description
focus onfocus When the user focuses on an element
submit onsubmit When the user submits the form
blur onblur When the focus is away from a form element
change onchange When the user modifies or changes the value of a form element

窗口/文档事件

Event Performed Event Handler Description
load onload When the browser finishes the loading of the page
unload onunload When the visitor leaves the current webpage, the browser unloads it
resize onresize When the visitor resizes the window of the browser

让我们讨论事件及其处理程序的一些示例。

点击事件


 Javascript Events 


MouseOver事件


 

Javascript Events

Keep cursor over me

焦点活动


 Javascript Events

Enter something here

按键事件


 Javascript Events

Enter something here

载入事件


Javascript Events