2012-12-19 50 views
6

我開發爲WordPress的模板頁,我需要當我點擊一個按鈕的路徑是namesite.com/wordpress/test加載圖像,我需要加載圖像在WordPress加載圖像使用jQuery

$("<img src='wp-content/themes/twentytwelve/images/loader.gif' class='loader' />").appendTo("#contact"); 

的問題是圖像不在wordpress/wp-content/themes/twentytwelve/images/loader.gif中搜索,但在wordpress/test/wp-content/themes/twentytwelve/images/loader.gif,所以我有錯誤。我能怎麼做?

回答

5

在'img src'的前面加上'/'從根開始。例如:

$("<img src='/wordpress/wp-content/themes/twentytwelve/images/loader.gif' class='loader' />").appendTo("#contact"); 
+1

謝謝!我添加了完整路徑;) – Mitro