运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <script> function whichElement(e) { let targ, tname, e; if (!e) { e = window.event; } if (e.target) { targ=e.target; } else if (e.srcElement) { targ=e.srcElement; } tname = targ.tagName; alert("You clicked on a " + tname + " element."); } </script> </head> <body onmousedown="whichElement(event)"> <h1>JavaScript HTML Events</h1> <h2>The onmousedown Attribute</h2> <p>Click somewhere in the document. An alert box will alert 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> </body> </html>