44.@鼠标点击页面中的任意标签,alert该标签的名称
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了44.@鼠标点击页面中的任意标签,alert该标签的名称相关的知识,希望对你有一定的参考价值。
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>
<!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该标签的名称的主要内容,如果未能解决你的问题,请参考以下文章