我有一张这样的表:
<thead>
<tbody>
<tr data-index="0">
<td>
<i class="fa fa-check"></i>
</td>
<td>....</td>
<td>....</td>
<td>
<a class="fa fa-file-o"></a>
<a class="fa fa-close"></a>
</td>
</tr>
<tr....
如何在第一个&lt;&fa;中更改jquery类“fa fa-check”到“fa fa-ban”? td&gt;并删除最后一个&lt; td&gt; (fa-file-o和fa-close)在data-index =“0”的行中?
答案 0 :(得分:2)
你可以做这样的事情
$('tr[data-index="0"]') // <-- this will get the td with data-index 0
.find('td:first .fa-check').addClass('fa-ban').removeClass('fa-check') // <-- this will get the first td and replace fa-check to fa-ban
.end() // <-- this will refer back to the tr with data index 0 initially referenced
.find('td:last').empty(); // <-- this will search the last td and empty it
你需要.end()因为在jquery获得带索引0的tr然后在第一个td内迭代之后我们需要遍历到父tr,以便可以捕获最后一个td。
$('tr[data-index=0]')
.find('td:first .fa-check').addClass('fa-ban').removeClass('fa-check')
.end()
.find('td:last').empty();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr data-index="0">
<td>
<i class="fa fa-check"></i>
</td>
<td>....</td>
<td>....</td>
<td>
<a class="fa fa-file-o"></a>
<a class="fa fa-close"></a>
</td>
</tr>
</table>
答案 1 :(得分:0)
首先:
$(".fa fa-check").addClass('fa-ban').removeClass('fa-check')
编辑:
$('tr[data-index="0"]').find('td:first .fa fa-check').addClass('fa-ban').removeClass('fa-check')