jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery ui sortable tablerows刷新号码位置里面大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
一个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

说明..它循环遍历表中的每个tr标签,然后用索引值tr修改一个td-child的内容

大佬总结

以上是大佬教程为你收集整理的jquery ui sortable tablerows刷新号码位置里面全部内容,希望文章能够帮你解决jquery ui sortable tablerows刷新号码位置里面所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。