forked from Rain120/Web-Study
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseover和mouseenter的区别.html
51 lines (50 loc) · 1.33 KB
/
mouseover和mouseenter的区别.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
50
51
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>mouseove & mouseout和mouseenter & mouseleave</title>
<style>
div {
border: 1px solid red;
height:50px;
line-height: 50px;
}
#b1, #b2 {
border: 1px solid green;
}
</style>
</head>
<body>
<div id="con1">
<button id="b1">mouseove & mouseout</button>
</div>
<p id="demo1"></p>
<div id="con2">
<button id="b2">mouseenter & mouseleave</button>
</div>
<p id="demo2"></p>
<script>
var over = 0
var out = 0
var enter = 0
var leave = 0
// mouseover
document.getElementById('con1').addEventListener('mouseover', function() {
document.getElementById('demo1').innerHTML = 'mouseover ' + over++
})
//mouseout
document.getElementById('con1').addEventListener('mouseout', function() {
document.getElementById('demo1').innerHTML = 'mouseout ' + out++
})
//mouseenter
document.getElementById('con2').addEventListener('mouseenter', function() {
document.getElementById('demo2').innerHTML = 'mouseenter ' + enter++
})
//mouseleave
document.getElementById('con2').addEventListener('mouseleave', function() {
document.getElementById('demo2').innerHTML = 'mouseleave ' + leave++
})
</script>
</body>
</html>