<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>事件对象</title>
<style>
#evg{
width: 300px;
height: 100px;
border: 1px solid black;
}
#showMsg{
width: 300px;
height: 80px;
border: 1px solid black;
}
</style>
<script>
window.onload = function(){
var evg = document.getElementById('evg');
var showMsg = document.getElementById('showMsg');
evg.onmousemove = function(event){
// 解决事件对象兼容性问题
event = event ? event : window.event;
var x = event.clientX;
var y = event.clientY;
showMsg.innerHTML = "x="+x+",y="+y;
}
}
</script>
</head>
<body>
<div id="evg"></div>
<br>
<div id="showMsg"></div>
</body>
</html>
网友评论