我想通過這個數組迭代到地圖上的引腳,在每個瀏覽器中它似乎工作正常,但在IE8中我得到錯誤「SCRIPT5007:無法獲取屬性的值'top':object is null or undefined「如果我將top改成別的東西或刪除它,IE只是說左邊或者名字相同的東西等。如果有人有任何建議,他們將不勝感激。Json對象屬性undefined只在IE8中
jQuery(document).ready(function(){
var pins = [
{ "name":"Mexico", "top":"154" , "left":"176", "imageFile":"Mexico.jpg", "soundMP3File":"Mexico_GMartinez_1.mp3", "soundOGGFile":"Mexico_GMartinez_1.ogg"},
{ "name":"Chile", "top":"261" , "left":"246", "imageFile":"Chile.jpg", "soundMP3File":"Chile_MVelasquez_1.mp3", "soundOGGFile":"Chile_MVelasquez_1.ogg"},
{ "name":"Trinidad and Tobago", "top":"182" , "left":"242", "imageFile":"TrinidadTobago.jpg", "soundMP3File":"Trinidad-Tobago_SHarris_1.mp3", "soundOGGFile":"Trinidad-Tobago_SHarris_1.ogg"},
{ "name":"Columbia", "top":"209" , "left":"227", "imageFile":"Columbia.jpg", "soundMP3File":"Colombia_JGordon_2.mp3", "soundOGGFile":"Colombia_JGordon_2.ogg"},
{ "name":"Canada", "top":"86" , "left":"208", "imageFile":"Canada.jpg", "soundMP3File":"Canada_KBretzer_1.mp3", "soundOGGFile":"Canada_KBretzer_1.ogg"},
];
for(var i = 0; i < pins.length; i++)
{
jQuery('#map #pins-container').append('<a href="#" class="pin" style="top: ' + pins[i].top + 'px; left:' + pins[i].left + 'px;" pinindex="' + i + '" name="' + pins[i].name + '"></a>');
}
});
你有數組中的最後一個對象後尾隨逗號。刪除。 – Guffa 2013-02-25 14:51:28