[英]Json object property undefined in IE8 only
I'm trying to iterate through this array to pins on a map, in every browser it seems to work fine but in IE8 I get the error "SCRIPT5007: Unable to get value of the property 'top': object is null or undefined" If I change top to something else or remove it, IE just says the same thing about left or name, etc. If anyone had any suggestions, they would be greatly appreciated. 我试图通过此数组迭代到地图上的引脚,在每个浏览器中似乎都可以正常工作,但是在IE8中,我收到错误消息“ SCRIPT5007:无法获取属性'top'的值:对象为null或未定义”如果我将顶部更改为其他名称或将其删除,则IE只会说左或名称等内容。如果有人有任何建议,将不胜感激。
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 is right. @古法是正确的。 The trailing comma on the 'Canada' line is invalid.
“加拿大”行上的尾部逗号无效。
IE is the only browser that will actually complain abuot it, but it is techinically invalid everywhere. IE是唯一会真正抱怨它的浏览器,但是从技术上讲,它在所有地方都是无效的。
In order to avoid issues like this, you should use tools like JSHint , which will validate your Javascript code for coding common errors, including the trailing comma bug. 为了避免出现此类问题,您应使用JSHint之类的工具,该工具将验证您的Javascript代码以编码常见错误,包括结尾的逗号错误。
In IE If you give comma after last JSON object this is give error in IE6,IE7,IE8. 在IE中,如果在最后一个JSON对象后输入逗号,则这是IE6,IE7,IE8中的错误。
So, Always remember this When ever you are writing Javascript,JSON 所以,永远记住这一点每当您编写Javascript,JSON时
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.