<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <!--第一种传参方式--> <div id="div1" onclick="func1(this)">hello1 </div> <script> function func1(self) { console.log(self.getAttribute("id")) } </script> <!--第二种传参方式--> <div id="div2">hello2 </div> <script> document.getElementById("div2").onclick = function () { console.log(this.getAttribute("id")) //不用传参,可直接使用this } </script> </body> </html>