【问题标题】:Moving table row td data up and down except first td of that row to re-order data向上和向下移动表行 td 数据,除了该行的第一个 td 以重新排序数据
【发布时间】:2013-09-24 20:08:59
【问题描述】:

我一直在尝试使此工作正常进行,以便在用户向上或向下移动该行中的其他数据时,一行的第一个 td(位置)不会移动。

jsFiddle:http://jsfiddle.net/qjd8w/6/

$(document).ready(function(){
    $('.up, .down').click(function(e){
        e.preventDefault();
        var row = $(this).parents("tr:first").children().not(':first'); 
        //causes error

        if ($(this).is(".up")) {
            row.insertBefore(row.prev());
        } 
        else {
            row.insertAfter(row.next());
        }
    });
});

var row = $(this).parents("tr:first") -- 其本身具有预期的效果,但这会随着行的其余部分上下移动位置。

我根本不希望位置移动,所以它会一直保持有序(1、2、3、4)

非常感谢任何帮助。

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    一种选择是简单地重新编号第一列:

    http://jsfiddle.net/FWCJm/

    $('tbody tr td:first-child').each(function(idx, item) {
        $(this).text(idx+1);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2012-07-18
      • 1970-01-01
      相关资源
      最近更新 更多