我已经动态创建了以下 javascript 对象(来自 PHP):
var t_feed = '';
t_feed += '[';
t_feed += '{name: "Tom Thumb", thumbnail: "images/Tom_Thumb.jpg", link: "http://twitter.com/cnnbrk/statuses/121630545879900161", description: "This is the body of the tweat"},';
t_feed += '{name: "Tom Thumb", thumbnail: "images/Tom_Thumb.jpg", link: "http://twitter.com/cnnbrk/statuses/121622456363524097", description: "This is the body of the tweat"},';
t_feed += '{name: "Tom Thumb", thumbnail: "images/Tom_Thumb.jpg", link: "http://twitter.com/cnnbrk/statuses/121614678341320706", description: "This is the body of the tweat"}';
t_feed += ']';
twitterFeeds[0] = eval(t_feed);
这在 IE8+ 中工作正常,但在 IE7 中出现以下错误:
SCRIPT5007: Unable to get value of the property 'thumbnail': object is null or undefined.
当我尝试像这样访问缩略图属性时,我得到了这个:
$.each(twitterFeeds[id], function(i,item){
alert(item.thumbnail);
});
为什么这在 IE7 中会失败,是否有不同的方法来定义一个列表或对象将起作用?
最佳答案
As a general rule, if you’re using eval() there’s probably something wrong with your design.
您可能想尝试将此字符串解析为 JSON而不是使用 eval(),然后从那里开始工作。
关于Javascript 对象在 IE7 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7665613/