为什么Internet Explorer不喜欢这个jQuery? [英] Why does Internet Explorer not like this jQuery?
问题描述
在调试某些在IE中无法使用的jQuery时,我发现了此错误消息:
While debugging some jQuery that is not working in IE, I found this error message:
var item = $("#item_"+ itemArray[itemIndex]).find('a').text().trim();
Object doesn't support this property or method (script.js, line 100, character 2)
character 2
对我来说没有意义.根据显示的文本,character 2
将是var
中的字母a
,但是当然没有任何意义.
The character 2
doesn't make sense to me. Based on the text displayed character 2
would be the letter a
in var
but of course that doesn't make any sense.
(我不应该使用var
吗?)
(Should I not use var
?)
我知道jQuery在某种程度上可以正常工作,或者脚本无法在我的页面上做到这一点.
I know that jQuery is working to some extent or the script would not have been able to get this far on my page.
推荐答案
IE没有 String.trim()
,则需要 $.trim()
(它会使用本机修剪(如果可用),并在IE中进行仿真),如下所示:
IE doesn't have String.trim()
, you'll need $.trim()
(which uses native trim if available, emulates it in IE), like this:
var item = $.trim($("#item_"+ itemArray[itemIndex]).find('a').text());
这篇关于为什么Internet Explorer不喜欢这个jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!