2013-02-13 38 views
1

我有一個html頁面(對於ex index.html),它有10個鏈接10個位置,每次用戶點擊任何鏈接時,不同類型的內容必須加載到單個動態的div。 div必須放置在jquery modal中。div實際上只在html頁面內(index.html),但div內容根據用戶點擊URL加載模式。我如何實現這一點?我是新來的jQuery和JavaScript。在點擊或Url鏈接上加載不同內容到單個div上

+2

歡迎來到StackOverflow!你嘗試過什麼嗎?請顯示您的代碼,以便有人能夠提供幫助。查看[關於頁面](http://stackoverflow.com/about)瞭解更多關於如何在這裏提出問題的信息... – 2013-02-13 01:47:11

+0

我並不是想把它放在另一個頁面上,內容已經在div中,但它必須在彈出窗口中彈出,這可以通過模態完成。但問題是模式中的內容必須基於url點擊進行動態加載 – user1765427 2013-02-13 01:57:36

回答

0

我能想到的最簡單的方法是使用jQuery .load()函數。使用非常簡單,它在選擇器上運行,並將選定元素加載到HTML頁面的子集中。因此,如果你的div被稱爲「fred」,並且你想將另一個頁面上的一個叫做「bob」的div的文本放到名爲fred的div中,你可以使用類似這樣的東西:

$('## fred')。load('http://alice.com/carol.html #bob');

它在鏈接頁面上有相當好的記錄。

0

嘗試這樣:

HTML

<div id="dialog-modal" title="Basic modal dialog"> 
    <p>Adding the modal overlay screen makes the dialog look more prominent because 
    it dims out the page content.</p> 
</div> 

<div id="somedivwithcontent1" style="display:none"> 
    Text to put into the modal dialog. 
</div> 

JS

var link = 1; //get from clicked link 
    $("#dialog-modal p").html($('#somedivwithcontent'+link).html()); 
    $("#dialog-modal").dialog({ 
    height: 140, 
    modal: true 
    }); 

此代碼將得到#somedivwithcontent的div的內容,並將其放置到的段落模態對話框。應該達到你想要的。

相關問題