2013-08-27 54 views
-1

我想用自己的ID開始這種格式id="IT_BGJ_I_...." 例如擰下兩顆<tr>標籤之間<tr>標籤具有指定格式的身份識別碼

<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>標籤之間的所有<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> 

從他們。 頂部和底部的IDS將開始使用jQuery或JavaScript

回答

4

你可以做到這一點使用^ jQuery選擇這表明IDClass或者是啓動任何attribute格式"IT_BGJ_I_....."

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

OR

,我可以看到你想要刪除DOMid開始與AB_,這樣你就可以通過

$('tr:[id^="AB_"])').remove() 
3

attribute-equals-selector

^attribute-starts-with-selector做到這一點

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(); 
+0

'tr'和'''''你不覺得它不會選擇任何東西嗎? –

+1

@DipeshParmar已更正。 –

相關問題