1

我从 ajax 请求返回了以下 html 数据

        <div> Log information from the following sessions
        <span class="comments"> your comments </span>
        <div>
        <div>Section B log information
        <span class="comments"> section B comments </span>
        </div>

这是我试图从这个返回 ajax 请求中删除所有评论类但没有工作并且评论没有被删除的尝试。

    $.ajax{
             url: pathToFile,
             success: function(data)
             {
                var removeComments = $(data).remove(".comments");
               alert(removeComments).html());
             }
          }
4

2 回答 2

2

首先找到(".comment")然后remove()

 var removeComments = $(data).find(".comments").remove().html();
 alert(removeComments));
于 2013-06-15T20:52:37.780 回答
1

使用.remove()这种方式 -

 $.ajax {
     url: pathToFile,
     success: function (data) {
         var removeComments = $(data).find('.comments').remove();
         alert(removeComments.html());
     }
 }

演示--> http://jsfiddle.net/UMVyQ/2/

于 2013-06-15T20:52:13.030 回答