<分区>
标签 javascript jquery html css
<分区>
我有一个非常简单的网站,其中包含一组 div,包括横幅(全宽)、左侧菜单(200 像素)和右侧内容(600 像素)。我有五个菜单项,它们使用简单的 jquery 脚本在单击时加载右侧内容。一切正常,除了无法打开的谷歌地图。当我转到 localhost/contact.html 时,它加载正常,所以功能就在那里。它只是不喜欢嵌入到整个文档/html 中。
菜单代码:
$(document).ready(function() {
$("#about").on("click", function() {
$("#content").load("about-us.html");
});
$("#candidate").on("click", function() {
$("#content").load("candidate.html");
});
$("#client").on("click", function() {
$("#content").load("client.html");
});
$("#meet").on("click", function() {
$("#content").load("meet.html");
});
$("#contact").on("click", function() {
$("#content").load("contact.html");
});
});
contact.html 代码
<body>
<script type="text/javascript" src="js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
var myCenter = new google.maps.LatLng(51.510252,-0.086585);
function initialize()
{
var mapProp = {
center: myCenter,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
var marker = new google.maps.Marker({
position: myCenter,
animation:google.maps.Animation.BOUNCE
});
marker.setMap(map);
}
</script>
<table border="3px">
<tr><td align="right">
t: <br>
1st Floor<br>
Regis House<br>
45 King William Street<br>
London, EC4R 9AN
</td>
<td id="googleMap" width="300px" height="300px">
</td>
</tr>
</table>
<script type="text/javascript">initialize('googleMap');</script>
</body>
刚刚用 chrome 嗅探并看到这个错误:
Uncaught ReferenceError: google is not defined VM500:1
(anonymous function) VM500:1
o.extend.globalEval jquery-2.1.0.min.js:2
o.fn.extend.domManip jquery-2.1.0.min.js:3
o.fn.extend.append jquery-2.1.0.min.js:3
(anonymous function) jquery-2.1.0.min.js:3
o.access jquery-2.1.0.min.js:2
o.fn.extend.html jquery-2.1.0.min.js:3
(anonymous function) jquery-2.1.0.min.js:4
j jquery-2.1.0.min.js:2
k.fireWith jquery-2.1.0.min.js:2
x jquery-2.1.0.min.js:4
(anonymous function)
最佳答案
我是个笨蛋……这最终很容易解决……因为我是主索引的一个组件,简单的 js 正在切换,我只需要将 API 调用放入主索引。 html 而不是 child ......所以感动了这个
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
进入 index.html ...一切正常..现在我有一个不同的问题,在使用 Firefox 时将 map 放置在...IE 和 Chrome 代码很好,但 Firefox 将 map 构建到整个页面..
关于javascript - 让谷歌地图出现在特定的 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21812349/