[英]Problems with global variable Javascript and jQuery
So I am trying to make script when u press for example "1" then click mouse to send position of cursor, but i have problems with global variables and functions namely with mX
and mY
因此,当您按例如“ 1”然后单击鼠标以发送光标的位置时,我试图制作脚本,但是全局变量和函数(即
mX
和mY
$('#A').on("mousemove", function (e) { mX = e.pageX });
$('#A').on("mousemove", function (e) { mY = e.pageY });
...
else if (code == 49) {f(vX, vY, mX, mY);}
...
function f(vX, vY, mX, mY) {
$('#A').click(function (e) {
var dX = Math.abs(vX - mX); <<< Here is the problem the mX is not defined
var dY = Math.abs(vY - mY);
});
The problem line i singed as <<<
i can't come with up how to solve it, i have make the variables in function to global. 我所称的问题行是
<<<
我无法解决该问题,我已将函数中的变量设置为global。
Do not pay attention about code
, vX
, vY
theese variables are working fine! 不要关注
code
, vX
, vY
这些变量工作正常!
Please, refer to How to pass argument to a jquery function through an onClick event? 请参阅如何通过onClick事件将参数传递给jquery函数?
function f(vX, vY, mX, mY) {
$('#A').click({mX:mX, mY:mY}, function (e) {
var dX = Math.abs(vX - e.data.mX);
var dY = Math.abs(vY - e.data.mY);
});
hope that's good for you 希望对你有好处
bye 再见
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.