<html>
<head>
<style>
div{
border: 1px solid black;
width: 500px;
height: 500px;
}
</style>
<script>
window.onload = function(){
document.body.onmousedown = function(event){
var mouseStartX = event.clientX;
var mouseStartY = event.clientY;
document.body.onmousemove = function(event){
var div = document.getElementsByTagName("div");
div[0].innerHTML = event.clientX + " " + event.clientY;
}
};
};
</script>
</head>
<body>
<div>
</div>
</body>
</html>
这是我的代码,我只希望我的鼠标光标位置仅在我同时触发 onmousedown 和 onmousemove 事件时触发,这意味着我在鼠标周围单击并拖动。