2011-01-07 87 views
0

基本上,我很懶,我只是希望jQuery在我的WordPress主題中爲我更新圖像URL。 WordPress的,通常你必須這樣做:如何將WordPress主題目錄添加到每個img src w/jQuery開頭

<img src="<?php bloginfo('template_url'); ?>/images/ect.png" alt="" /> 

但是我想在jQuery中做的是得到它的動態替換

<img src="images 

<img src="<?php bloginfo('template_url'); ?>/images/ 

我希望它自動確定博客URL,我不想手動設置它,如果這是有道理的。對於精通WP的人應該很容易。

任何想法?

+0

你爲什麼不只是使用一個適當的IDE並使用一個名爲「在文件中替換」的功能,用jquery執行它比用幾個按鈕更難。 – 2011-01-07 08:43:26

+0

記事本++就足夠完成這項任務! – ifaour 2011-01-07 08:57:33

回答

0

@comment:

$('img').hide(); 

$('img').each(function(index){ 
    $(this).attr('src', 'http://your-url'+$(this).attr('src')).fadeIn('slow'); 
}); 

您可以使用任何數字,1000例如,而不是'slow''slow'意味着600個mSeconds長)

$(this).attr('src', 'http://your-url'+$(this).attr('src')).fadeIn(1000); 
0

試試這個

$('img').each(function(index){ 
    $(this).attr('src', 'http://your-url'+$(this).attr('src')); 
}); 

http://api.jquery.com/attr/ http://api.jquery.com/each/

注意,jQuery的客戶端上運行,所以如果你要插入PHP代碼,它將不會被執行。但是,您可以將<?php bloginfo('template_url'); ?>傳遞給腳本,在'http:// your-url'中。