2012-08-30 70 views
0

我試圖在圖像之前添加文本。該圖像沒有默認的類/ id。 的代碼是這樣的:在img src之前添加文本

$('.status img').attr('src', 'LINK IMAGE').after('My text'); 

編輯: 完整代碼:

$('.status img').attr('src', 'LINK IMAGE1').after('My text1'); 
$('.status img').attr('src', 'LINK IMAGE2').after('My text2'); 
$('.status img').attr('src', 'LINK IMAGE3').after('My text3'); 

回答

0

HTML:

<ul> 
<li class="status">T1<img /></li> 
<li class="status">T2<img /></li> 
<li class="status">T3<img /></li> 
</ul> 

的JavaScript:

var imgArray = new Array('http://cache2.allpostersimages.com/p/LRG/20/2070/7T92D00Z/posters/bitte-im-sitzen-pinkeln.jpg', 'http://cache2.allpostersimages.com/p/LRG/20/2070/7T92D00Z/posters/bitte-im-sitzen-pinkeln.jpg', 'http://cache2.allpostersimages.com/p/LRG/20/2070/7T92D00Z/posters/bitte-im-sitzen-pinkeln.jpg'); 
var count = 1; 

$('.status').children('img').each(function(){ 
    $(this).attr('src', imgArray[count]); 

});