运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body onclick="myFunction(event)" style="border:1px solid black;Padding:8px"> <h1>HTML DOM Events</h1> <h2>The currentTarget Property</h2> <p>Click on any elements in this document to find out which element triggered the onclick event.</p> <p>The target property does not return the element that was clicked on, but the element which triggered the event.</p> <p id="demo"></p> <script> function myFunction(event) { let element = event.currentTarget; document.getElementById("demo").innerHTML = element; } </script> </body> </html>