我試圖製作一個html表格,用戶可以通過向上和向下箭頭來排序行。但有一個字段我想讓它保持不變,id字段。更改表格行的順序,除了一列jquery
HTML代碼:
<table class="table routes_t">
<thead>
<tr>
<th>#</th>
<th>Local</th>
<th>Coordenadas</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="ord">1</td>
<td>Template2</td>
<td>37.13318,-8.5392</td>
<td>
<span class="id" data-id="9"></span>
<a href="#" onclick="remove(9)" "=""><i class="glyphicon glyphicon-remove pull-right"></i></a>
<a href="#" class="uporder"><i class="glyphicon glyphicon-arrow-down pull-right"></i></a>
<a href="#" class="downorder"><i class="glyphicon glyphicon-arrow-up pull-right"></i></a>
</td>
</tr>
<tr>
<td class="ord">2</td>
<td>Teste_unserial</td>
<td>37.13008,-8.54247</td>
<td>
<span class="id" data-id="10"></span>
<a href="#" onclick="remove(10)" "=""><i class="glyphicon glyphicon-remove pull-right"></i></a>
<a href="#" class="uporder"><i class="glyphicon glyphicon-arrow-down pull-right"></i></a>
<a href="#" class="downorder"><i class="glyphicon glyphicon-arrow-up pull-right"></i></a>
</td>
</tr>
</tbody>
</table>
和我的jQuery是:
$(document).ready(function(){
$(".uporder,.downorder").click(function(){
var row = $(this).parents("tr:first");
if ($(this).is(".downorder")) {
row.children('td:not(:first)').insertBefore(row.prev());
} else {
row.insertAfter(row.next());
}
});
});
現在發生什麼事是我想非觸摸的字段不變,但其他領域轉移到不必要的位置,像上面的
Thanks in推進
你能設置一個小提琴嗎? – Shashank 2014-09-19 09:47:58