2017-01-13 4 views
0

私は以下のような行IDをカウントを持つテーブルが含まれているIDとのTDを削除:jqueryのIDでこれらtdを削除何らかの理由でjQueryの偶数

<td class="text-center manage" id="sw-1" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-2" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-3" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-4" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-5" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-6" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-7" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-8" rowspan="2" width="20%"> 

を、私が使用するいくつかの「汚れ」作品をプレイしたいです偶数が含まれている、理想的には出力は次のようになります。

<td class="text-center manage" id="sw-1" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-3" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-5" rowspan="2" width="20%"> 
<td class="text-center manage" id="sw-7" rowspan="2" width="20%"> 

私がしました試み:

$('table td[id*="sw-"]').not(':even').remove(); 

が、目を付属していません。私が望む結果。

をお伝えください。

+0

'$( 'TR TD:でも')。)(削除' –

+0

@Rory McCrossanさて、あなたは私を啓発、ありがとう!! –

答えて

0

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
     <script> 
 
     $(document).ready(function(){ 
 
      var i=$('table td'); 
 
      console.log(i); 
 
      \t $.each(i,function(k,v){ 
 
       \t var id=v.id.split('-'); 
 
       if(id[1]%2 == 0){ 
 
        $('#sw-'+id[1]).remove(); 
 
       } 
 
      }); 
 
     }); 
 
     </script> 
 
    </head> 
 
    <body> 
 
     <table> 
 
     <tr> 
 
      <td class="text-center manage" id="sw-1" width="20%">1</td> 
 
     </tr> 
 
     <tr> 
 
      <td class="text-center manage" id="sw-2" width="20%">2</td> 
 
     </tr> 
 
     <tr> 
 
      <td class="text-center manage" id="sw-3" width="20%">3</td> 
 
     </tr> 
 
     </table> 
 
    </body> 
 
</html>