我无法让这个工作。它将页面刷新为“未定义”,因此我甚至无法使用Firebug进行故障排除。任何人都可以向我指出这将返回undefined的哪一部分?
var locations = {
'us-lax': {
'name': 'Los Angeles'
},
'us-nyc': {
'name': 'New York'
}
};
// this is the order in which they'll appear
var all_locations = ['us-lax', 'us-nyc'];
function bar() {
$('#foo').prepend('<h3>foo</h3>');
for (i in all_locations) {
location = locations[all_locations[i]];
loc = $('<li></li>');
loc.html(location['name']);
loc.appendTo('#foo');
}
};
$(document).ready(function() {
bar();
});
答案 0 :(得分:4)
大多数浏览器都使用“location”这个名称。尝试为该变量使用不同的名称。
答案 1 :(得分:0)
是页面上ID为foo的元素吗?