Home > Article > Web Front-end > What is event source in javaScript?
In an event, the element currently being operated is the event source. For example, input in a web page element has an onclick event. When input is clicked to send an onclic event, the event source is input. The event source exists as an attribute of the event object. You can use the srcElement attribute to obtain the event source.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In the event, the element currently operated on is the event source. For example, the input in the web element has an onclick event. When the input is clicked to send an onclic event, the event source is the input.
Common event sources:
(Mouse) Event | Description |
---|---|
onclick | Triggered when the mouse clicks on the object |
ondblclick | Triggered when the mouse double-clicks the object |
onmousedown | Triggers when the mouse button is pressed |
onmousemove | Triggers when the mouse is moved |
onmouseout | Triggered when the mouse leaves the element or sub-element listening to this event |
onmouseover | The mouse moves to Triggered when the element or sub-element listening to this event |
onmouseup | Triggered when the mouse is released |
(Keyboard) Event | Description |
---|---|
Keyboard press | |
Keyboard hold | |
Keyboard release |
Description | |
---|---|
Losing focus | |
Getting focus | |
Input | |
Change | |
submit | |
Reset |
Description | |
---|---|
End of page loading | |
Scroll | |
Change the size |
Get the event source:
The event source exists as a property of the event object of. In the W3C specification, this attribute is target; however, IE8.0 and below does not support this attribute, and it uses the srcElement attribute to obtain the event source.<html> <head> <title>获取事件源</title> </head> <body> <div id="demo">点击这里</div> <script type="text/javascript"> document.getElementById("demo").onclick=function(e){ var eve = e || window.event; var srcNode = eve.target || eve.srcElement; // 兼容所有浏览器 alert(srcNode); } </script> </body> </html>For more programming-related knowledge, please visit:
Programming Video! !
The above is the detailed content of What is event source in javaScript?. For more information, please follow other related articles on the PHP Chinese website!