gpt4 book ai didi

javascript - Google map 仅在 IE7 中无法加载 : 'Unexpected call to method or property access'

转载 作者:行者123 更新时间:2023-12-02 20:20:58 25 4
gpt4 key购买 nike

我有一个 map ,当用户单击按钮时,它会初始化谷歌地图。这会触发运行此方法的事件:

$self.maps = {
loadMap : function(){
var canvasDom = "map";
var latlng = new google.maps.LatLng(40.7608, -111.8910);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$self.vars.maps.map = new google.maps.Map(document.getElementById(canvasDom), myOptions);
},
//other methods in the object for handling other maps stuff...
};

当调用最后一行来创建新 map 时,出现以下错误:“SCRIPT65535:意外调用方法或属性访问。”main.js,第 31 行字符 347

它似乎中断的代码行是:

a[Va](b);

所有这些都适用于 Firefox、Chrome、IE8 和 IE9,以及我尝试过的所有浏览器,除了 IE7(使用 IE9 的兼容模式)。

更新:我已经设置了 JSFiddle for this ,以相同的方式初始化 map ,只是由于某种原因它不会重现我在应用程序中遇到的 IE7 错误。我不太确定这说明了这个问题。

最佳答案

经过几个小时痛苦地注释掉寻找冲突的脚本后,我开始手动粘贴在创建 map 时正在运行的代码块。最终,我将其归咎于罪魁祸首。

看看这个:

//set that the map is open, and
//should remain so if the user searches again
$('form').append('<input type="hidden" name="map" value="true">');

$('#search-list-map')
.removeClass('listview')
.addClass('mapview');

//show map, hide list
$('#map').removeClass('hide');
$('#listResults').addClass('hide');

//initialize the map
$self.maps.loadMap();

loadMap() 是我在上面的问题中引用的方法。 注意到我附加到表单中的输入字段了吗? 事实证明,如果有一个元素的 name 与 map div 的 id 相同>,并且该元素出现在 DOM 中的 map div 之前,将会抛出错误。据我所知,这种情况只会出现在IE7中(可能是IE6,我无法测试)。

我已经在 J​​SFiddle 上重现了该错误,here 。在IE7下运行它,你就会成功。

关于javascript - Google map 仅在 IE7 中无法加载 : 'Unexpected call to method or property access' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5568815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com