在一个html表中,我在每一行中都有一个单元格,它有自己的位置编号.使用jQueryUI进行排序后,如何正确刷新此位置号码?
这是我简单的html:
<table border="0"> <thead> <tr> <th scope="col">Position number</th> <th scope="col">Name</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Text</td> </tr> <tr> <td>2</td> <td>Text</td> </tr> </tbody> </table>
这是我的js:
var fixHelper = function(e,ui) { ui.children().each(function() { $(this).width($(this).width()); }); return ui; }; $("table tbody").sortable({ helper: fixHelper }).disableSelection();
现在,我想在完成排序后更改订单的位置编号值.
我该怎么做?
任何帮助将被释放.
提前致谢.
解决方法
排序后进行以下操作
$("table tbody").sortable({ update: function(event,ui) { $('table tr').each(function() { $(this).children('td:first-child').html($(this).index()) }); },helper: fixHelper }).disableSelection();
你可以尝试(未经测试):
而不是$(‘table tr’),每个都使用$(this).parents(‘table’).find(‘tr’).each