我尝试在图片前添加文字。该图像没有默认的类/ 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');
答案 0 :(得分: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]);
});