我正在使用AngularJS框架,我在jQuery中使用'hasClass'为了让鼠标悬停在下拉菜单上。它在Chrome和FF中工作正常,但在IE中,当我单击按钮并导航到另一页时,它提供了一个错误,“无法获取属性hasClass的未定义或空引用”。 这个错误并不是每次都显示出来,但它经常出现在IE中。 同样,有时候不是'hasClass',它会抛出'height'为未定义或空引用。 这里是代码:无法获取未定义的属性'hasClass'或空引用
(function ($, window, delay) {
var theTimer = 0;
var theElement = null;
var theLastPosition = { x: 0, y: 0 };
$('[data-toggle]')
.closest('li')
.on('mouseenter', function (inEvent) {
if (theElement) theElement.removeClass('open');
window.clearTimeout(theTimer);
theElement = $(this);
theTimer = window.setTimeout(function() {
theElement.addClass('open');
}, delay);
})
.on('mousemove', function (inEvent) {
if (Math.abs(theLastPosition.x - inEvent.ScreenX) > 4 ||
Math.abs(theLastPosition.y - inEvent.ScreenY) > 4) {
theLastPosition.x = inEvent.ScreenX;
theLastPosition.y = inEvent.ScreenY;
return;
}
if (theElement.hasClass('open')) return;
window.clearTimeout(theTimer);
theTimer = window.setTimeout(function() {
theElement.addClass('open');
}, delay);
})
.on('mouseleave', function (inEvent) {
window.clearTimeout(theTimer);
theElement = $(this);
theTimer = window.setTimeout(function() {
theElement.removeClass('open');
}, delay);
});
})(jQuery, window, 50); // 50 is the delay in milliseconds
有什么建议吗? 谢谢。
我们怎么没有看到任何代码暗示什么吗? – adeneo 2014-09-10 23:24:13
@Oriol:谢谢,你能提供更新的代码吗? – Madhav 2014-09-10 23:37:56
应该把这个角度指令 – charlietfl 2014-09-10 23:53:23