运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html> <body onmousedown="whichElement(event)"> <h1>HTML DOM Events</h1> <h2>The onmousedown Event</h2> <p>Click somewhere in the document. I will display the name of the element you clicked on.</p> <h3>This is a heading</h3> <img border="0" src="smiley.gif" alt="Smiley" width="32" height="32"> <p>This is a paragraph.</p> <div id="demo"></div> <script> function whichElement(e) { let targ; if (!e) { let e = window.event; } if (e.target) { targ = e.target; } else if (e.srcElement) { targ = e.srcElement; } let tname = targ.tagName; document.getElementById("demo").innerHTML = "You clicked on a " + tname + " element."; } </script> </body> </html>