我在 jquery 中使用 mousemove 时遇到问题。我想在 mousedown 事件和 mousemove 事件之后检查鼠标指针的坐标,但它只更新一次,结果只是 mousedown 事件发生时的坐标。
我真的需要一些建议,谢谢:)
我在这里只发布了原始代码的一小段摘录:
附注我尝试使用“$(document).ready(function(){”,但没有成功。
<!DOCTYPE html>
<head>
<title>jQuery Test</title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" language="javascript">
function my_func(event){
$("#log1").html("mouse is down");
var x = $(this);
//some code
$(document).ready(function(){
x.on("mousemove", function(){
$("#log1").html("x:"+event.pageX+" y:"+event.pageY);
});
});
}
$(document).ready(function(){
$("button").on("mousedown",my_func); //it needs to be a named function because I will call it multiple times
});
</script>
</head>
<body>
<button >TEST</button>
<div id="log1"></div>
</body>
</html>
最佳答案
改变
x.on("mousemove", function(){
到
x.on("mousemove", function(event){
JsFiddle -> http://jsfiddle.net/6y83H/
关于jquery - mousemove 事件仅在 mousedown 后更新一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23384483/