2014-02-21 101 views
0

我目前遇到一些与OOP JavaScript相关的IE8错误。一切工作正常在IE9 +,铬,火狐等我也试图找到类似的问题,在stackoverflow,但失败。OO JS对象不支持此属性或方法在IE8中

代码:

$(function(){ 
    // Notification 
    OPD_Notification = function(selector) { 
     this.selector = selector; 
    } 

    OPD_Notification.prototype.setText = function(text) { 
     $(this.selector).find('.container').text(text); 
    }; 

    OPD_Notification.prototype.setStatus = function(status) { 
     $(this.selector).addClass(status); 
    } 

    OPD_Notification.prototype.removeStatus = function(status) { 
     $(this.selector).removeClass(status); 
    } 

    OPD_Notification.prototype.show = function() { 
     $(this.selector).slideDown(200); 
    }; 

    OPD_Notification.prototype.hide = function() { 
     $(this.selector).slideUp(200); 
    }; 

    // Notification 
    notification = new OPD_Notification('#notification'); 
}); 

问题: IE8引发我一个错误Object doesn't support this property or method,当我尝试做以下操作:notification = new OPD_Notification('#notification');我猜它可能是做与jQuery,但真的不知道。

就像我运行代码低音,它在IE8中工作正常。

function Rabbit(line) { 
    this.line = line; 
} 

Rabbit.prototype.speak = function() { 
    alert(this.line); 
}; 

rbt = new Rabbit("Well, now you're asking me."); 
rbt.speak(); 

关于我在做什么错误的任何提示,将有很大帮助。谢谢。

JSFiddle

+1

你的变量应该是全球性的吗? – elclanrs

+0

@elclanrs是的。因为我想在其他一些功能中使用它。 –

+0

这是否有帮助:https://github.com/socketstream/socketstream/issues/283#issuecomment-7835157 – Oleg

回答

0

不知道怎么了,不知道为什么。但我已将notification = new OPD_Notification('#notification');更改为prefixNotification = new OPD_Notification('#notification');并开始工作。

相关问题