2011-02-25 68 views
0

我想從另一個Ajax頁面加載背景圖片,我不知道什麼是最好的方法嗎?使用jquery從其他頁面加載背景圖像?

在我的index.html頁面我有css後臺代碼,我想從另一個asp頁面加載圖像。

我的index.html文件,因爲它現在看起來:

<div id="bgimage" style="background-image: url(../images/theimage.jpg); background-repeat: no-repeat; background-position: center center; background-attachment:fixed;"> 

,並從數據庫得到正確的圖像imagepage.asp頁面。

<div id="menuimage"> 
<img src="..user_images/<%=folderName%>/menuimage/<%=rs("big_image")%>" id="themenyimage"/> 
</div> 

任何建議appriciated,謝謝。

回答

0

沿東西線

var temp_div = $('<div></div>'); 
temp_div.load('path.asp #menuimage', function() { 
    $('#bgimage').css('background-image', temp_div.find('img').first().attr('src'); 
}); 

大概可以優化等

+0

感謝布萊爾,但它不工作,我不明白爲什麼我怕。 – 2011-02-25 17:25:33

+0

您可能需要進行一些調試。確保你獲得了結果,確保圖像確實存在,請嘗試將temp_div放入DOM以確保它加載等等。對不起,我不能進一步幫助。 – 2011-02-25 17:30:19

+0

是的,我會這樣做,謝謝。 – 2011-02-25 17:37:13