我想从jQuery BlockUI插件生成的模态中获取cursorX坐标。
当我尝试使用下面的代码这样做时,它给出“ cursorX is not defined(..)”错误。
document.onmousemove = function(e){
cursorX = e.pageX;
cursorY = e.pageY;console.log('dsahg');
}
cursorX;
最佳答案
是的,它没有定义。您需要使用var
进行定义
console.log(cursorX);//see this its a undefined .its not defined by anything before
var cursorX=""; // default value is empty
var cursorY ="" // default value is empty
document.onmousemove = function(e){
cursorX = e.pageX;
cursorY = e.pageY;console.log(cursorX);
}
console.log(cursorX); //its a defined one .but pass the default empty value.Beacuse its show with window load .not after the mouse move