Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery ui可排序表行刷新内部编号位置_Jquery_Jquery Ui_Html Table_Jquery Ui Sortable - Fatal编程技术网

jQuery ui可排序表行刷新内部编号位置

jQuery ui可排序表行刷新内部编号位置,jquery,jquery-ui,html-table,jquery-ui-sortable,Jquery,Jquery Ui,Html Table,Jquery Ui Sortable,在html表格中,我在每一行中都有一个单元格,它有自己的位置号。使用jQueryUI排序后,如何正确刷新此职位编号 这是我的简单html: <table border="0"> <thead> <tr> <th scope="col">Position number</th> <th scope="col">Name</th> </tr> &

在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>
现在,我想在完成排序后正确地改变顺序定位数字值

我怎么做这个


如有任何帮助,将不胜感激。

请在排序后执行以下操作

$("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)。父项('table')。查找('tr')。每个

解释。。
它循环遍历表中的每个
tr
标记,然后使用
tr

的索引值更改第一个
td child
的内容。如果有人像我一样喜欢上面的答案,下面是咖啡脚本

jQuery ->
  $("ul.sortableEdit").sortable
            stop: (event, ui) ->  
             $('ul.sortableEdit li').each( ->
               $(this).children('input.sortableItemPos').val($(this).index())
             )

非常感谢你,回答得好,解释得好,效果很好。我接受并投票支持你的答案,如果你愿意,你也可以对我的问题这样做。谢谢!也帮了我-很好的回答和问题
jQuery ->
  $("ul.sortableEdit").sortable
            stop: (event, ui) ->  
             $('ul.sortableEdit li').each( ->
               $(this).children('input.sortableItemPos').val($(this).index())
             )