2013-05-30 49 views
0

我做了這些鏈接側菜單:加載HTML頁面的特定專區內一些PHP鏈接?

<div id="menu_lat"> 
    <a href="http://localhost:8080/sgf/form_proposta.php">Orçamentos</a> 
    <a href="relatorios.html">Relatórios</a> 
    <a href="proximos.html">Próximos Eventos</a> 
    <a href="chat.html">Chat</a> 
</div> 

當我打開其中的一個,內容是在另一個DIV(其中,在第一頁中,已經有一些內容,這是一個圖片)打開:

<div id="conteudo"> 
    <img src="img/foto_inicial.jpg"> 
</div> 

當我點擊該鏈接時,如何加載此層中的PHP文件?

+1

你可以做一個'框架'設置,但我不建議這樣做。您也可以將JavaScript函數運行並改變conteudo div的HTML內容,以從該頁面返回的HTML。沒有時間爲你編寫代碼,但這些都是我的想法。 – JClaspill

+1

您將無法包含的任何PHP指令(S)在'.html'文件,除非你使用'AddHandler的應用程序/ X的httpd - PHP的.html .htm'在'.htaccess'文件。你可以使用iframe,但這可能會使事情變得複雜。如果將整個文件結構更改爲'.php',將會更容易。使用JS是好的,但如果用戶禁用JS,你會怎麼做?然後你就上了那條小溪。 ;-) –

回答

3

使用jQuery和load()功能

更新與類鏈接

<div id="menu_lat"> 
    <a class="loader" href="http://localhost:8080/sgf/form_proposta.php">Orçamentos</a> 
    <a class="loader" href="relatorios.html">Relatórios</a> 
    <a class="loader" href="proximos.html">Próximos Eventos</a> 
    <a class="loader" href="chat.html">Chat</a> 
</div> 

然後在你的<script>標籤添加此處理點擊與類加載器鏈接的事件。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> 
<script type="text/javascript"> 
$(function() { 
    $('.loader').click(function(event) { 
     event.preventDefault(); // stop the link loading the URL in href 
     $('#conteudo').load($(this).attr('href')); 
    }); 
}); 
</script> 
+0

我只想補充一點,我的腳本標記,我能在我的網頁使用jQuery?我還沒有學習它,既沒有Ajax。 :/ – rsb2097

+0

鏈接加載整個頁面 – rsb2097

+1

您還需要包括jQuery庫本身的網址,看到更新的答案 – fullybaked

1

做Ajax調用的DIV ID conteudo

相關問題