jQuery ui可排序的表格刷新数字位置
在一个html表中,我在每一行都有一个具有自己位置编号的单元格。 在使用jQueryUI进行排序后,如何正确刷新此位置编号?
这是我的简单html:
Position number Name 1 Text 2 Text
这是我的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').each
使用$(this).parents('table').find('tr').each
说明..它循环遍历表中的每个tr
标记,然后使用索引值tr
更改第一个td-child
的内容
如果有人像我一样喜欢上述答案,那么这就是Coffeescript
jQuery -> $("ul.sortableEdit").sortable stop: (event, ui) -> $('ul.sortableEdit li').each( -> $(this).children('input.sortableItemPos').val($(this).index()) )