案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
function whichElement(e)
5
{
6
var targ
7
if (!e) var e = window.event
8
if (e.target) targ = e.target
9
else if (e.srcElement) targ = e.srcElement
10
if (targ.nodeType == 3) // defeat Safari bug
11
   targ = targ.parentNode
12
var tname
13
tname=targ.tagName
14
alert("You clicked on a " + tname + " element.")
15
}
16
</script>
17
</head>
18
19
<body onmouseup="whichElement(event)">
20
<p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>
21
22
<h3>This is a header</h3>
23
<p>This is a paragraph</p>
24
<img src="/img/eg_mouse2.jpg"  alt="Ball" />
25
</body>
26
27
</html>