最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why does Internet Explorer not like this jQuery? - Stack Overflow

programmeradmin4浏览0评论

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)

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.

(Should I not use var?)

I know that jQuery is working to some extent or the script would not have been able to get this far on my page.

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)

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.

(Should I not use var?)

I know that jQuery is working to some extent or the script would not have been able to get this far on my page.

Share Improve this question asked Nov 30, 2010 at 15:46 Roger BarrRoger Barr 412 bronze badges 4
  • 2 Why? Because it is Internet Explorer. – user142019 Commented Nov 30, 2010 at 15:49
  • This has been asked before: stackoverflow./questions/2308134/… Basically, it looks like IE does not have trim() built-in. – Orbling Commented Nov 30, 2010 at 15:50
  • 2 possible duplicate of .trim() in JavaScript not working in IE – Stephen Commented Nov 30, 2010 at 15:52
  • @Stephen - That's a non-jQuery question, the optimal answer differs. – Nick Craver Commented Nov 30, 2010 at 16:02
Add a ment  | 

2 Answers 2

Reset to default 19

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());

IE doesn't have a trim method.

Instead, you can call jQuery.trim(...).

发布评论

评论列表(0)

  1. 暂无评论