简体   繁体   English

仅在IE8中未定义的Json对象属性

[英]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.

相关问题 无法获取属性“ call”的值:对象为null或未定义的IE8 - Unable to get value of the property 'call': object is null or undefined IE8 在ie8 jQuery错误中(属性“ $”的值为null或未定义,不是Function对象) - In ie8 jquery error(The value of the property '$' is null or undefined, not a Function object) 对象不支持此属性或方法-仅IE8? - Object does not support this property or method - IE8 only? 仅限IE8 - 对象不支持属性或方法'小部件' - IE8 only - Object doesn't support property or method 'widget' Object仅在IE8上不支持此属性或方法 - Object doesn't support this property or method only on IE8 自定义js / jQuery代码仅在IE7和IE8上生成错误:对象不支持此属性或方法 - Custom js/jQuery code is generating error only on IE7 & IE8: Object does not support this property or method jQuery ie8对象为空或未定义 - jQuery ie8 Object Null or undefined IE8中未定义onchange事件对象 - onchange event object undefined in IE8 SCRIPT5007:属性onclick =“ JavaScript:functionName(&#39;name&#39;,&#39;2&#39;,&#39;0&#39;)的值为null或未定义,不是Function对象(ie8) - SCRIPT5007: The value of the property onclick="JavaScript:functionName('name', '2', '0') is null or undefined, not a Function object(ie8) Microsoft JScript运行时错误:无法获取属性“ radalert”的值:对象为null或未定义IE8 - Microsoft JScript runtime error: Unable to get value of the property 'radalert': object is null or undefined IE8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM