JavaScript event source

The event source exists as a property of the event object. 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.

Get 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>



Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭