Javascript 对象在 IE7 中不工作

标签 javascript

我已经动态创建了以下 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/

相关文章:

javascript - 全屏组件 ReactJS

javascript - 响应式棋色元素

javascript - 在 Ajax Adob​​e AIR 应用程序中与 API 共享 secret

javascript - dojo 中的状态服务器端过滤

javascript - 在 Google Maps API v3 中获取自定义图 block 的中心 LatLng 点

javascript - 按下按钮时在 URL 中发布数据

javascript - Ember GroupableMixin 使用 groupProperty

javascript - 即使页面发生变化,在点击时也显示 AJAX 请求?

javascript - 如何制作这个 Gauge 微分 Angular ?

javascript - yuicompressor-maven-plugin 似乎忽略了我的排除/包含选项