onmousedown - 当按下鼠标时:提示点击了哪个元素
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function whichElement(e) {
- var targ;
- if (!e) {
- var e = window.event;
- }
- if (e.target) {
- targ=e.target;
- } else if (e.srcElement) {
- targ=e.srcElement;
- }
- var tname;
- tname = targ.tagName;
- alert("您点击了 " + tname + " 元素。");
- }
- </script>
- </head>
- <body onmousedown="whichElement(event)">
-
- <h1>卢浦大桥</h1>
- <img border="0" src="/i/shanghai_lupu_bridge.jpg" alt="卢浦大桥" />
- <p>卢浦大桥,位于中国上海市原卢湾区与浦东新区之间的黄浦江上,曾经是世界上主拱桥最长的拱桥、钢拱桥。</p>
- <p><b>(单击文档中的某个位置。警告框将提示您单击的元素的名称。)</b></p>
- </body>
- </html>