0

我试图在图像之前添加文本。该图像没有默认的类/ID。代码是这样的:

$('.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');
4

1 回答 1

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]);

});
于 2012-08-30T18:06:22.357 回答