gpt4 book ai didi

jquery - mousemove 事件仅在 mousedown 后更新一次

转载 作者:行者123 更新时间:2023-12-01 04:49:21 24 4
gpt4 key购买 nike

我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com