0

我有一个无序列表:

html:

<ul id="blogs">
   <li>
     <a class="vimg" href="/blogs/news/6875583-hurricane-sandy">
      <img src="mydomainvideo_icons.jpg?1542">
    </a>
 </li>
    <a href="/blogs/news/6875583-hurricane-sandy">
      <strong class="titlen">Hurricane Sandy</strong>
      <p class="newsp">lorem ispum lorem ispumu...</p>
    </a>
    <a class="readp" href="/blogs/news/hurricane-sandy">Read More</a>
 <li></li>
 <li></li>
</ul>

我想用jQuery改变上面的html,所以输出如下:

  <ul id="blogs">
   <li>
      <a class="vimg" href="/blogs/news/6875583-hurricane-sandy">
       <img src="mydomainvideo_icons.jpg?1542">
     </a>
     <a href="/blogs/news/6875583-hurricane-sandy">
       <strong class="titlen">Hurricane Sandy</strong>
       <p class="newsp">lorem ispum lorem ispumu...</p>
    </a>
    <a class="readp" href="/blogs/news/hurricane-sandy">Read More</a>
 </li>
 <li></li>
 <li></li>

这是我拥有的 jquery,但它不起作用:

jQuery:

  $("#blogs li").each(function(){

       if ($(".video-container").length > 0  && $(this).children('img').length == 0){
          var vidindex = $('.readp').attr('href')
          $(this).find('.video-container').remove();
          $(this).append('<a class="vimg" href=""><img src="{{ 'video_icons.jpg' | asset_url }}"/></a>');
          $('.titlen').appendTo('.vimg')
          $(this).find('a').attr("href", vidindex)
     }
      $(this).find('img').replaceWith(function(){ return '<img src="'+this.src+'"/>';});
});
4

1 回答 1

4

在列表项中附加锚标记

$("#blogs").find("li").append("<a href='#'>some Description</a>");
于 2012-11-13T05:03:27.667 回答