-1

我想删除<tr>两个标签之间的所有<tr>标签,它们的 id 以这种格式开头id="IT_BGJ_I_...." 例如

<tr id="IT_BGJ_I_6262626_IW_7373737_IWL_4></tr>
<tr id="AB_C"></tr>
<tr id="AB_D"></tr>
<tr id="AB_R"></tr>
<tr id="IT_BGJ_I_434343_IW_4343434_IWL_4></tr>
<tr id="IT_BGJ_I_45456_IW_7373737_IWL_4></tr>
<tr id="AB_F"></tr>
<tr id="AB_G"></tr>
<tr id="AB_RE"></tr>
<tr id="IT_BGJ_I_443433_IW_4343434_IWL_4></tr>

我需要删除

  <tr id="AB_C"></tr>
    <tr id="AB_D"></tr>
    <tr id="AB_R"></tr>

<tr id="AB_F"></tr>
<tr id="AB_G"></tr>
<tr id="AB_RE"></tr>

从他们。顶部和底部 id 将以"IT_BGJ_I_....." 使用 jQuery 或 javascript的格式开头

4

3 回答 3

4

您可以使用^jQuery 选择器来执行此操作,该选择器指示ID或以Class任何attribute开头。

$('tr:not([id^="IT_BGJ_I_"])').remove()

或者

如我所见,您想删除DOMid开头的AB_,因此您可以通过

$('tr:[id^="AB_"])').remove()
于 2013-08-27T09:57:42.347 回答
3

属性等于选择器

^ 属性以选择器开始

Description: Selects elements that have the specified attribute with 
a value beginning exactly with a given string.

代码

$('tr:not([id^="IT_BGJ_I_"])').remove();

或者

$('tr[id^="AB_"])').remove();
于 2013-08-27T09:57:55.393 回答
1

或尝试:not

$("tr:not([id^='IT_BGJ_I_'])").remove();

小提琴:http: //jsfiddle.net/SawmJ/11/

于 2013-08-27T10:01:35.250 回答