为了..参加加时赛但仅限于 IE8?
我尝试过自己解决这个问题,但我没有想法。
我有一个循环,仅通过循环数组来创建列表项。但它似乎每次都会执行额外的循环,因此会拉出未定义的元素。例如,我的数组停在 albums[0] 处,但它会继续尝试对不存在的 albums[1] 执行此操作。奇怪的是,更具体地说,它最终从我的过滤功能中提取文本?
为什么在 chrome 中不会发生这种情况? 这就是 ie8 中发生的情况 http://dl.dropbox.com/u/1261672/groovyBox2222/guts/artists.html?Hackers-vs-Slackers&
getPlaylist(function(songs) // pulls out songs matching artist
{
var albums = new Array();
for (obj in songs){
if (songs[obj]["artist"] == artist){
albums.push(songs[obj]["album"]);
}
albums = removeDuplicateElement(albums);
}
var albumname;
for (x in albums){ // creates LI of albums
albumname = '<li><a href="albums.html?'+escape(albums[x])+
'&'+escape(artist)+'">'+albums[x]+"</a></li>";
$('#albumlist').append(albumname);
}
};
I have tried figuring this out on my own but am out of ideas.
I have a loop that just makes list items by looping through an array. But it seems to be doing an EXTRA loop each time, therefore pulling an undefined element. e.g. my array stops at albums[0] but it goes ahead and tries to do it for albums[1] which doesn't exist. weirdness ensues, more specifically, it ends up pulling the text from my filter function??
how come this doesn't happen in chrome?
this is where it happens in ie8
http://dl.dropbox.com/u/1261672/groovyBox2222/guts/artists.html?Hackers-vs-Slackers&
getPlaylist(function(songs) // pulls out songs matching artist
{
var albums = new Array();
for (obj in songs){
if (songs[obj]["artist"] == artist){
albums.push(songs[obj]["album"]);
}
albums = removeDuplicateElement(albums);
}
var albumname;
for (x in albums){ // creates LI of albums
albumname = '<li><a href="albums.html?'+escape(albums[x])+
'&'+escape(artist)+'">'+albums[x]+"</a></li>";
$('#albumlist').append(albumname);
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
循环数组时切勿使用
for in
...这是不可预测的。使用这个代替:Never use
for in
when looping over an array... it's unpredictable. Use this instead:您正在使用“foreach”循环,这导致了问题。改为这样做:
You are using a 'foreach' loop, which is causing the problem. Do this instead: