错误类型null或不是对象

时间:2012-08-13 17:31:59

标签: internet-explorer javascript-events

我的代码在Firefox中完美运行,但我遇到了IE问题。当我执行时,我得到错误,程序没有正确执行。描述说clientX为null或不是对象。

var cursorLocation = new function(){
this.x = 0;
this.y = 0;
//This function is called onmousemove to update the stored position
this.update = function(e){
    var w = window, b = document.body;
    this.x =  e.clientX + (w.scrollX || b.scrollLeft || b.parentNode.scrollLeft || 0);
    this.y = e.clientY + (w.scrollY || b.scrollTop || b.parentNode.scrollTop || 0);
}}      document.onmousemove=function(e){ cursorLocation.update(e); };

1 个答案:

答案 0 :(得分:0)

你不应该在javascript中使用new function(){...}

有错误。


应该之类的事情

var someFunction = function(){....};

var someVariable = new someFunction();