码迷,mamicode.com
首页 > 其他好文 > 详细

44.@鼠标点击页面中的任意标签,alert该标签的名称

时间:2017-06-13 12:50:51      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:class   eve   hid   mil   open   pre   type   ext   har   

技术分享
 1 <!DOCTYPE html>
 2 <html>
 3 <head lang="en">
 4     <meta charset="UTF-8">
 5     <title>鼠标点击页面中的任意标签,alert该标签的名称</title>
 6     <style>
 7         div {
 8             background-color: blue;
 9             width: 150px;
10             height: 150px;
11             cursor: pointer;
12         }
13 
14         span {
15             background-color: #658050;
16             width: 120px;
17             height: 120px;
18             cursor: pointer;
19             display: block;
20         }
21 
22         p {
23             background-color: red;
24             width: 100px;
25             height: 100px;
26             cursor: pointer;
27         }
28     </style>
29     <script type="text/javascript">
30         document.onclick = function (evt) {
31             var e = window.event || evt;
32             var tag = e["target"] || e["srcElement"];
33             alert(tag.tagName);
34         };
35     </script>
36 </head>
37 <body>
38 <div id="div"><span>span</span>div</div>
39 <p>P</p>
40 </body>
41 </html>
View Code

 

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>鼠标点击页面中的任意标签,alert该标签的名称</title>
<style>
div {
background-color: blue;
width: 150px;
height: 150px;
cursor: pointer;
}

span {
background-color: #658050;
width: 120px;
height: 120px;
cursor: pointer;
display: block;
}

p {
background-color: red;
width: 100px;
height: 100px;
cursor: pointer;
}
</style>
<script type="text/javascript">
document.onclick = function (evt) {
var e = window.event || evt;
var tag = e["target"] || e["srcElement"];
alert(tag.tagName);
};
</script>
</head>
<body>
<div id="div"><span>span</span>div</div>
<p>P</p>
</body>
</html>

44.@鼠标点击页面中的任意标签,alert该标签的名称

标签:class   eve   hid   mil   open   pre   type   ext   har   

原文地址:http://www.cnblogs.com/mx2036/p/7000218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!