我在我的本地搜索应用程序中使用谷歌搜索 JSAPI。在除 IE 8 之外的所有浏览器中一切正常。问题是在我的 jquery 基础对象和 google 对象被 drreferenced 的特定代码行之后。
这是一个直接的代码。我能够使用 this jsfiddle 重现问题.
html代码是
<html>
<head>
<title>Test Map</title>
<script src="http://www.google.com/jsapi?" type="text/javascript"></script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>
和JS
$(function() {
alert(1);
google.load('search',1);
alert($);
google.setOnLoadCallback(function() {
alert(2);
});
});
在 google.load('search',1)
行之后我得到了以下错误
错误:对象不支持此属性或方法
$
和 google
。
这完全是一场噩梦。我为此奋斗了几个小时而没有运气。这里的 IE 专家有什么想法吗?
最佳答案
将您的 jsFiddle 更改为“No wrap (body)”并像这样修改您的函数...
//$(function() {
//alert(1);
google.load('search',1);
alert($);
google.setOnLoadCallback(function() {
alert(2);
});
//});
这里问的问题几乎相同:Google is not defined using Google Visualization API; possibly jQuery's fault
关于javascript - google.load 上 IE8 中的神秘 'object doesnt support this method' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9748331/