删除列表中的项目并使用jquery追加新项目

时间:2012-11-12 07:52:43

标签: jquery replace append

我有以下输出:

<ul id="blogs">

  <li>
      <a href="/blogs/news/6875583-hurricane-sandy">
      <div class="video-container">...</div>
     </a>
 </li>

   <a href="/blogs/news/6875583-hurricane-sandy">
   <strong id="title">Hurricane Sandy</strong>
   <p id="newsp">loremi ispum lor ismi smodi</p>
   </a>
 <a id="readp" class="rmore" href="/blogs/news/6875583-hurricane-sandy">Read More</a>

 <li>
   <a href="/blogs/news/6572743-floyd"></a>
   <div class="video-container">...</div>
   </a>
</li>

  <a href="/blogs/news/6572743-floyd"></a>
  <strong id="title">Hurricane Floyd</strong>
  <p id="newsp">loremi ispum lor ismi smodi</p>
  </a>
   <a id="readp" class="rmore" href="/blogs/news/6572743-floyd">Read More</a>


  <li>
  <a href="/blogs/news/6557987-fiji">
   <img li="" ...<="" src="//mydomain/A21E1A04F48C9B7F42333F72EB5A57D9.jpg?932">
    <strong id="title">Fiji.</strong>
   <p id="newsp">loremi ispum lor ismi smodi</p>
  </a>
   <a id="readp" class="rmore" href="/blogs/news/6557987-fiji">Read More</a>
  </li>


   </ul>

我想用jQuery编辑上面的输出,如下所示:

<ul id="blogs">
  <li>
     <a href="/blogs/news/6875583-hurricane-sandy">
      <img src="http://mydomain/video_icons.jpg?1212">
     </a>
     <strong id="title">Hurricane Sandy</strong>
     <p id="newsp">loremi ispum lor ismi smodi</p>
     <a id="readp" class="rmore" href="/blogs/news/6875583-hurricane-sandy">Read More</a>
  </li>

  <li>
      <a href="/blogs/news/6572743-floyd"></a>
      <img src="http://mydomain/video_icons.jpg?1212">
     </a>
     <strong id="title">Hurricane Floyd</strong>
     <p id="newsp">loremi ispum lor ismi smodi</p>
     <a id="readp" class="rmore" href="/blogs/news/6572743-floyd">Read More</a>
  </li>

  <li>
     <a href="/blogs/news/6557987-fiji">
      <img src="//mydomain/A21E1A04F48C9B7F42333F72EB5A57D9.jpg?932">
     </a>
    <strong id="title">Fiji.</strong>
    <p id="newsp">loremi ispum lor ismi smodi</p>
    <a id="readp" class="rmore" href="/blogs/news/6557987-fiji">Read More</a>

这是我的jQuery,但我遗漏了一些东西或者没有正确地写这个,所以我没有得到所需的输出:

jQuery的:

 $("#blogs li").each(function(i) {
    if ($(".video-container").length > 0  && $(this).children('img').length == 0){
      var vidindex = $('#readp').attr('href')
      $(this).find('a').replaceWith(function(){return '';});
      $(".video-container").remove();
      $(this).append('<a href=""><img src="{{ 'video_icons.jpg' | asset_url }}"/></a>');
      $(this).append($("#title"));
      $(this).append($('#newsp'));
      $(this).append($('#readp'))
      $(this).find('a').attr("href", vidindex)
  }
     $("#blogs li img").replaceWith(function(){
     return '<img src="'+this.src+'"/>';
   });
});

0 个答案:

没有答案