获取鼠标的当前坐标,可以用pageX or pageY就可以实现,代码特别的简单,代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>pageX or pageY</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(document).mousemove(function(e){
$(‘span‘).text(‘x:‘+e.pageX+‘px‘+‘ , y:‘+e.pageY+‘px‘);
});
});
</script>
</head>
<body>
<p>鼠标指针坐标:<span></span></p>
</body>
</html>
时间: 2024-10-07 04:18:21