/
demo.html
49 lines (44 loc) · 1.17 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>鼠标hover显示元素边框</title>
<style>
.tit {
width: 100px;
height: 100px;
background: red;
}
.tit {
width: 100px;
height: 50px;
background: red;
}
</style>
</head>
<body>
<div id="box" class="tit"></div>
<p class="tit">p</p>
<a class="tit1" href="www.baidu.com" alt="www.baidu.com">a</a>
<script>
function mouseOverShowBorder(container) {
const children = container.childNodes
for (let i = 0; i < children.length; i++) {
const child = children[i]
if (child.nodeType === 1) {
child.onmouseover = function() {
this.style.border = '1px solid #ccc'
}
child.onmouseout = function() {
this.style.border = ''
}
mouseOverShowBorder(child)
}
}
}
mouseOverShowBorder(document.body)
</script>
</body>
</html>