【问题标题】:Add text before img src在 img src 之前添加文本
【发布时间】:2012-08-30 17:56:33
【问题描述】:

我尝试在图像前添加文本。该图像没有默认的类/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');

【问题讨论】:

    标签: jquery text image add src


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-12
      • 1970-01-01
      相关资源
      最近更新 更多