Home > Web Front-end > JS Tutorial > body text

What is event source in javaScript?

青灯夜游
Release: 2023-01-06 11:17:07
Original
4757 people have browsed it

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.

What is event source in javaScript?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Event source

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
##onkeydownKeyboard presskeypressKeyboard holdkeyupKeyboard release
(Keyboard) Event Description
(Form Control) EventDescriptiononblurLosing focusonfocusGetting focusoninputInputonchangeChangeonsubmitsubmitonresetReset
(Page) Event DescriptiononloadEnd of page loadingonscrollScrollonresizeChange 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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template