运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body onclick="myFunction(event)"> <h1>The Element Object</h1> <h2>The tagName Property</h2> <p>Click on any elements in this document to see which element triggered the onclick event.</p> <button>This is a button</button> <p><span>This is span element.</span></p> <p id="demo"></p> <script> function myFunction(event) { const element = event.target; document.getElementById("demo").innerHTML = "Triggered by " + element.tagName; } </script> </body> </html>