我想使用jQuery更改表格单元格的位置。
— kiwi fruit
— Peach
— banana
green | fruit: kiwi fruit
pink | fruit: Peach
yellow | fruit: banana
Sour | fruit: kiwi fruit
sweet | fruit: Peach
sweet | fruit: banana
— kiwi fruit
green | fruit: kiwi fruit
Sour | fruit: kiwi fruit
— Peach
pink | fruit: Peach
sweet | fruit: Peach
— banana
yellow | fruit: banana
sweet | fruit: banana
"- [fruit]"
" | fruit: [fruit]"
* [水果]前的第二个,两个空格
<table>
<tr>
<td>— kiwi fruit</td>
</tr>
<tr>
<td>— Peach</td>
</tr>
<tr>
<td>— banana</td>
</tr>
<tr>
<td>green | fruit: kiwi fruit</td>
</tr>
<tr>
<td>pink | fruit: Peach</td>
</tr>
<tr>
<td>yellow | fruit: banana</td>
</tr>
<tr>
<td>Sour | fruit: kiwi fruit</td>
</tr>
<tr>
<td>sweet | fruit: Peach</td>
</tr>
<tr>
<td>sweet | fruit: banana</td>
</tr>
</table>
我在下面提供了资料,但这是不切实际的,因为其他水果,例如“苹果”,“樱桃”等。将来可以添加,每次添加新水果时,我都必须编辑源。
$("tr:contains(' | fruit: kiwi fruit')").insertAfter("tr:contains('— kiwi fruit')");
$("tr:contains(' | fruit: Peach')").insertAfter("tr:contains('— Peach')");
$("tr:contains(' | fruit: banana')").insertAfter("tr:contains('— banana')");
谢谢!
2天前我问了这个问题,但没有找到任何解决方案。 如果有人可以帮助我解决这个问题,那么我真的很乐意。