【发布时间】:2015-08-12 11:09:50
【问题描述】:
我正在使用以下代码。
var cursorXPos;
var cursorYPos;
$(document).mousemove( cursorLocation(evt) );
function cursorLocation (evt) {
cursorXPos = evt.pageX;
cursorYPos = evt.pageY;
}
但这给了我一个错误。
未捕获的类型错误:无法读取未定义的属性
pageX。
但是,如果我使用匿名函数,事件对象会被传递,一切正常。
$(document).mousemove( function (evt) {
cursorXPos = evt.pageX;
cursorYPos = evt.pageY;
});
【问题讨论】:
-
第一个 sn-p 执行
cursorLocation,然后使用它的返回值作为对实际事件处理程序的引用。您没有返回任何内容,因此引用将是undefined。
标签: javascript jquery events mouseevent mousemove