2016-02-11 48 views
1

我將second.html加載到#[email protected],並且我想使用second.html中的按鈕加載third.html到#[email protected],同時卸載第二個HTML在父級HTML中加載外部html到div

我成功地加載第二個HTML到第一個HTML使用load()。

我已經在second.html使用這種嘗試:

$("#button").click(function() { 
    $("#divcontainer".top.parent.document).unload("second.html"); 
    $("#divcontainer".top.parent.document).load("third.html"); 
    }); 

,但不工作。

http://i.imgur.com/CINb5Qj.jpg「結構」

+0

你使用[的jsfiddle(http://jsfiddle.net) –

+0

我還沒有創建一個樣本,怎麼就必須創建三個html文件。 –

+0

您使用的html代碼結構 –

回答

0

由於要素是動態加載,那麼你必須使用事件委派:

$('#divcontainer').on('click', '#button' function() { 
    $(this).parent().load('third.html'); 
}); 

,你不需要任何unload因爲它會取代現有的內容。

+0

我試過了,但不起作用。我把你的腳本放在second.html的按鈕所在的位置。 –

+0

@kikisutanto你可以在主頁上使用它。 – Jai