2012-09-04 34 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()語句放入加載的頁面中。