2010-11-18 61 views
1

單擊鏈接時是否可以觸發div的「刷新」?我已經在div中嵌入了一個js調用廣告服務器,鏈接中有很多參數,所以我無法讓.load工作,這是我可以提出的最佳解決方案。理想情況下,每次點擊鏈接(更改標籤)時,我都希望腳本(廣告內容)刷新並重新加載與頁面刷新時不同的廣告。這可能與jQuery的?鏈接點擊重新加載外部腳本

HTML的鏈接

<ul id="flowtabs"> 
    <li><a id="t1" href="#Brokers">Brokers</a></li> 
    <li><a id="t2" href="#Education">Educators</a></li> 
    <li><a id="t3" href="#Third-Party-Add-Ons">3rd Party Add-Ons</a></li> 
    <li><a id="t4" href="#NinjaScript-Consultants">NinjaScript Consultants</a></li> 
</ul> 

廣告容器是

<div id="quoteContain"> 
<!-- AdSpeed.com Serving Code 7.9.5 for [Zone] Testimonial 200x600 --> 
    <script type="text/javascript" src="http://g.adspeed.net/ad.php?do=js&amp;zid=XXXX&amp;wd=200&amp;ht=600&amp;target=_top"></script> 
    <noscript><iframe width="200" height="600" src="http://g.adspeed.net/ad.php?do=html&amp;zid=XXXXXX&amp;wd=200&amp;ht=600&amp;target=_top" frameborder="0" scrolling="no" > 
    <a href="http://g.adspeed.net/ad.php?do=clk&amp;zid=XXXXXX&amp;wd=200&amp;ht=600&amp;pair=as" target="_top"> 
    <img style="border:0px;" src="http://g.adspeed.net/ad.php?do=img&amp;zid=XXXXXX&amp;wd=200&amp;ht=600&amp;pair=as" alt="i" width="200" height="600"/></a></iframe> 
    </noscript><!-- AdSpeed.com End --> 
<!-- /quoteContain --></div> 

(使用AJAX請求)JS

$("ul#flowtabs li a").click(function){ 
    //need it to refresh here 
    $("#quoteContain").html(data); 
}); 
+0

請張貼您的代碼。 – 2010-11-18 15:36:59

+0

@Andy E - 抱歉代碼已發佈。 thx – 2010-11-18 15:41:11

回答

1

沒有「刷新div」之類的東西。

這些都是從我的頭頂,可以被「刷新」的部件(如觸發從數據源數據的新要求):圖像,CSS樣式表,閃存嵌入播放器等

你可以嘗試並「克隆」這個div,將它從dom中刪除,然後再次添加它。但我不確定它會起作用。

var clone = $("#yourdiv").clone(); 
$("#yourdiv").replaceWith(clone); 
0

是,有可能更新的div。

沒有Ajax的例子:

<div id="xxx"></div> 

,如果你的新內容是過網訪問做插入類似

$('#xxx').load('/path/to/xxx.html'); 

的情況下,你的內容是使用delieverd一個Ajax請求 - 使用結果並將其加載到div或其他html元素中

+0

@Thariama - 類似於$ .ajax {$(「#quoteContain」)。load(url?params)}?不知道我按照如何更新它。 thx – 2010-11-18 15:45:34

+0

我更新了我的代碼 – Thariama 2010-11-18 15:56:07

+0

@Thariama - 我似乎無法做到原始代碼bc我必須在我的div中使用 - – 2010-11-18 16:03:26

0

使用jQuery將內容加載到DOM中相當簡單。

function adContainerRefresh() { 
    $('#adCoontainer').clear().load(adServerUrl); 
} 

$('foo').click(function() { 
    adContainerRefresh(); 
    /* ... */ 
});