简体   繁体   English

Internet Explorer jQuery错误

[英]Internet Explorer JQuery Error

I am using JQuery min 1.4.2. 我正在使用JQuery min 1.4.2。 I have a function which iterates through a few tables and adds a class with a number attached: 我有一个遍历几个表并添加带有数字的类的函数:

$("#reportArea table", this).each(function(i){
$(this).addClass("table-" + i);
});

For some reason this throws an error in IE 8 and IE9, however, in Firefox and Chrome when I open console, I do not see any errors. 由于某些原因,这会在IE 8和IE9中引发错误,但是,在打开控制台的Firefox和Chrome中,看不到任何错误。 The error in IE is: IE中的错误是:

Message: Invalid argument.
Line: 48
Char: 1
Code: 0
URI: /js/jquery-min.js

If I look at line 48 in the IE debugger, I see this: 如果查看IE调试器中的第48行,则会看到以下内容:

a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue; etc.. 

I also tried rephrasing my code to this but still get the same error: 我也尝试将我的代码改写为此,但仍然出现相同的错误:

$('#reportArea table:eq(0)').addClass('table-0');
$('#reportArea table:eq(1)').addClass('table-1');

The odd part is that the class still gets added to the tables in IE. 奇怪的是,该类仍被添加到IE中的表中。

Note, I would add the classes manually but it's a JSP Report page and I don't have access to the specific template that controls this page. 注意,我将手动添加类,但这是“ JSP报告”页面,并且我无权访问控制该页面的特定模板。

$("#reportArea table", this).each(...
                       ^^^^

What is this in here? 什么是this会在这里? It should be a DOM context . 它应该是DOM上下文 I don't think you need it for your selector as ids are (should be) unique. 我认为您的选择器不需要它,因为id是(应该是)唯一的。 If you're not calling that function inside a specific function, the this keyword might reference the global object and therefore cause the error. 如果未在特定函数内调用该函数,则this关键字可能引用全局对象,因此会导致错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM