gpt4 book ai didi

javascript - 触发焦点/模糊事件时获取鼠标位置?

转载 作者:太空狗 更新时间:2023-10-29 14:54:13 25 4
gpt4 key购买 nike

我正在使用 jQuery 来捕获事件:

$('input').focus(function(e){

console.log( e.pageX, e.pageY );

});

这似乎不起作用...关于获取鼠标位置的替代方法有什么想法吗?


很有帮助。

最佳答案

您只能使用鼠标事件获取鼠标坐标。如果你想捕捉鼠标的位置,你可以使用一个全局的 mousemove 事件监听器,并将坐标存储在一组变量中,稍后可以通过 focus功能。示例:

var pageX, pageY; //Declare these globally
$(window).mousemove(function(e){
pagex = e.pageX;
pageY = e.pageY;
});

$('input').focus(function(){
console.log(pageX, pageY); // These variables have been defined by the global
// mousemove event
});

关于javascript - 触发焦点/模糊事件时获取鼠标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7984725/

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