我正在注册 mousemove
处理程序,代码如下:
http://jsfiddle.net/cbsub/2/ 在Chrome和Firefox上测试过。
其中一部分代码为:
$("body").on("mousemove", function () {
console.log("$('body') mousemove listener invoked");
});
$("#foo").on("mousemove", function () {
console.log("$('#foo') mousemove listener invoked");
});
但出于某些原因,它们从未被调用,但是 mousemove
的 html
、document
和 window
处理程序将被调用。我是否忽略了什么?
undefined
没有onmousemove
属性。如果在页面加载后,我有意输入document.getElementsByTagName("foobarwahlah")[0].onmousemove = function () {}
,那么它会说TypeError: Cannot set property 'onmousemove' of undefined
。 - Jeremy LUncaught TypeError: Cannot set property 'onmousemove' of undefined
。然而,你的问题可能是时机不对。如果你把它们放在 ready 下面或者 html 元素之后(body 的末尾),那么它应该可以正常工作。 - PSLdocument.getElementsByTagName("body")[0]
被包含在head中而不是在window.onload或document.ready中,也会抛出错误,这是理论上的情况,实际上我大多数时候都是这样看到的。 - PSL