我有一个包含计数行id的表,如下所示:
<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%">出于某些原因,我想玩一些‘泥土’工作,以使用jquery删除这些id包含偶数的td,理想的输出是:
<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();但是没有得到我想要的结果。
请给我建议。
发布于 2017-01-13 18:11:01
<!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);
$.each(i,function(k,v){
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>
https://stackoverflow.com/questions/41631079
复制相似问题