我已根据<td>
s&#39;成功对表格行进行了排序。内容(表格单元格为&#39;文本&#39;),所以为了细化细节,我必须:
text
的每个表格单元格的内容。对于每个细胞:
(
.split()
返回的数组中获取第一个项,并将其推送至names1
names1
那么,我的问题是如何按字母顺序排序/排序?
$(document).ready(function() {
$("table .text").each(function() {
var this_current = $(this);
$(this).addClass("dirty");
var text = $(this).text().replace('(', '').replace(')', '').replace(' ', '');
$("table .text:not(.dirty)").each(function() {
var text2 = $(this).text().replace('(', '').replace(')', '').replace(' ', '');
if (text >= text2) {
$(this).closest('tr').prev().prev().prev().before(this_current.closest("tr"));
} else {
$(this).closest('tr').after(this_current.closest("tr"));
}
});
$(this).removeClass("dirty");
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<tr>
<td>table cell of the 1st row</td>
</tr>
<tr>
<td>table cell of the 2nd row</td>
</tr>
<tr>
<td>table cell of the 3rd row</td>
</tr>
<tr>
<td class="text">ILIGAN (DALIPUGA)</td>
</tr>
<tr>
<td>table cell of the 5th row</td>
</tr>
<tr>
<td>table cell of the 6th row</td>
</tr>
<tr>
<td>table cell of the 7th row</td>
</tr>
<tr>
<td class="text">ILIGAN (BB)</td>
</tr>
<tr>
<td>table cell of the 9th row</td>
</tr>
<tr>
<td>table cell of the 10th row</td>
</tr>
<tr>
<td>table cell of the 11th row</td>
</tr>
<tr>
<td class="text">ILIGAN (BB)</td>
</tr>
<tr>
<td>table cell of the 13th row</td>
</tr>
<tr>
<td>table cell of the 14th row</td>
</tr>
<tr>
<td>table cell of the 15th row</td>
</tr>
<tr>
<td class="text">CDO (AGUSAN)</td>
</tr>
<tr>
<td>table cell of the 17th row</td>
</tr>
<tr>
<td>table cell of the 18th row</td>
</tr>
<tr>
<td>table cell of the 19th row</td>
</tr>
<tr>
<td class="text">ILIGAN (AA)</td>
</tr>
<tr>
<td>table cell of the 20th row</td>
</tr>
<tr>
<td>table cell of the 21th row</td>
</tr>
<tr>
<td>table cell of the 22th row</td>
</tr>
<tr>
<td class="text">ILIGAN (JJ)</td>
</tr>
</table>
&#13;