target与currentTarget的区别
我的理解在下面的代码中显示,currentTarget比target来的更具体些,点那个就是哪个
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>target与currentTarget区别</title> <style> #box{ width: 500px; height: 200px; background-color: blue; } </style> </head> <body> <div onclick="getClick(event)" id="box"> <h1 onclick="getClick(event)" id="boxh">我是h1标签</h1> </div> <script> var box = document.querySelector('#box'); var boxh = document.querySelector('#boxh'); function getClick(event){ a = event.currentTarget; b = event.target; alert("currentTarget 指向: " + a.id + ", target指向:" + b.id) } </script> </body> </html>