2

我正在使用 Moovweb SDK 来转换我的博客站点,并且我有一个评论列表,如下所示:

<ul class="commentlist">
  <li class="comment" id="li-comment-131126">
    <div id="comment-131126">
      <div class="comment-author vcard">
        Comment from <cite class="fn" id="tevfik_sertel01">Tevfik Sertel</cite>
      </div>
      <p>I'm so great!</p>
    </div>
  </li>
  <li class="comment" id="li-comment-131127">
    <div id="comment-131127">
      <div class="comment-author vcard">
        Comment from <cite class="fn" id="jimmy_page01">Jimmy Page</cite>
      </div>
      <p>You're really not that great.</p>
    </div>
  </li>
  <li class="comment" id="li-comment-131129">
    <div id="comment-131129">
      <div class="comment-author vcard">
        Comment from <cite class="fn" id="roger_waters_07">Roger Waters</cite>
      </div>
      <p>You're actually kind of a bore.</p>
    </div>
  </li>
</ul>

因为它们很荒谬,所以我想摆脱所有不是 tevfik 写的评论。

或者更确切地说,删除具有其 id 不包含 tevfik 的引用的 lis。

我该怎么做?

4

1 回答 1

2

您可以将范围限定在条件方括号内,如下所示:

$(".//li[.//cite[not(contains(@id, 'tevfik'))]]") { 
  remove() 
}

或者更简单,直接使用 remove() 函数:

remove(".//li[.//cite[not(contains(@id, 'tevfik'))]]")
于 2013-06-10T20:09:44.827 回答