2012-09-04 37 views
0

我遇到了一个问题,我似乎无法解决加载包含谷歌地图的页面内容。以下是包含父标题和google api信息的index.php页面。谷歌地图和jquery.Load问题

<html> 
<head> 
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.7.2.min.js"></script> 

    <!-- Google Maps --> 
    <script src="http://maps.google.com/maps/api/js?sensor=false"></script> 
    <script type="text/javascript"> 
     function initialize() { 
     var mapOptions = { 
      center: new google.maps.LatLng(-34.397, 150.644), 
      zoom: 8, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     var map = new google.maps.Map(document.getElementById("location-wedding"), 
      mapOptions); 
     } 
    </script> 
    <!-- Switch Layout --> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      $('.Theme_Page').load("test.php"); 
     }); 
    </script> 


</head> 


<body onload="initialize()"> 

    <!-- Page Change --> 
    <div class="theme_holder"> 

    </div> 

    <div class="Theme_Page"> 
     <!-- Content To Go Here --> 
    </div> 

</body> 

在被加载的页面是以下内容:

<div id="location-wedding" style="width:700px; height:250px"></div> 

问题是如果上述DIV是在index.php内,那么地图存在,只要它将它放在要加载的页面中,它根本不显示。为什么我要它在.load()页面的原因是因为我打算使用Jquery来更改此页面上的内容(使用onclick事件)

任何帮助或指导都是最受赞赏。

干杯李。

+0

'load(“test.php”,initialize)'试试这个吗? – Val

+0

嗨瓦尔,这工作,唯一的争议是,当点击更改内容按钮时,地图(也出现在其他HTML页面正在加载)消失。代码是: $('。theme_holder:button')。click(function(){ var page = $(this).attr('href'); $(“#theme-loading”)。html ('Loading'); setTimeout(function(){$('。Theme_Page')。load(''+ page +'。php',null,function(){(“#theme-loading”)。 html(''); });},150); return false; }); \t }); 再次感谢。 – HireLee

回答

0

由于yoda说你的初始化函数在load.php加载之前就会启动。所以不会有div在哪里的JavaScript可以把地图,而不是从身体onload调用初始化函数,你应该在load.php中调用这个函数.....试试这个::从身体删除onload函数和地方下面的JavaScript代码加载.php

<script type="text/javascript"> 
    $(document).ready(function() { 
     initialize() 
    }); 
</script> 
+0

感谢Yoda和Suresh,我在.load()加载的所有页面上添加了上面的JS,它可以正常工作。但是,通过将JS放置在这些页面的顶部,这些加载在页面中的页面没有头标记(因为父页面具有主体标记和头标记)会被认为是不好的做法?由于JS不在文档的头部? – HireLee

+0

理想情况下,您应该在'head'中调用所有脚本文件,但函数调用可能发生在任何地方。 – Yoda

0

有人猜测,因为onload="initialize()"test.php div之前加载。将initialize()语句放入加载的页面中。