我在 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>
Change
x.on("mousemove", function(){
to
x.on("mousemove", function(event){
JsFiddle->http://jsfiddle.net/6y83H/ http://jsfiddle.net/6y83H/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)