<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" id="btn">
<script>
window.onload = function() {
var btn = document.getElementById('btn');
var fun = function (event) {
switch (event.type){
case "click":
alert('1');
break;
case "mouseover":
alert('2');
break;
}
};
btn.onclick = fun;
btn.onmouseover = function (event) {
//立刻停止事件在DOM层次中的传播,所以这边onmouseover的时候不会弹出2。如果去掉这个方法,会弹出2
event.stopPropagation('mouseover');
}
}
</script>
</body>
</html>