event chrome firefox 获取点击对象的 id 类

 

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<p onclick="e0()" id="id0" class="class0">e0</p><br>
<p onclick="e1()" id="id1" class="class1">e1</p>
</body>
</html>
<script>
function e0(){
c(event);
}
function e1(){
var event = window.event
c(event);
}
function c(e){
console.log('--->');
console.log(e);
console.log(e.target);
console.log(e.target.getAttribute('id'));
console.log(e.target.getAttribute('class'));
}
</script>

 

 

 

https://developer.mozilla.org/en-US/docs/Web/API/Event

  1. MDN
  2.  
  3. Web technology for developers
  4.  
  5. Web APIs
  6.  
  7. Event

 

The Event interface represents any event which takes place in the DOM; some are user-generated (such as mouse or keyboard events), while others are generated by APIs (such as events that indicate an animation has finished running, a video has been paused, and so forth). There are many types of event, some of which use are other interfaces based on the main Event interface. Event itself contains the properties and methods which are common to all events.

posted @ 2017-03-02 11:35  papering  阅读(245)  评论(0编辑  收藏  举报