在html表中上下移动行

Man*_*han 4 html javascript

可能重复:
在JQuery中交换行

如何在某个按钮点击中在表格中上下移动行?

cam*_*aca 7

尝试使用jQuery.你可以这样做:

<table id="mytable">
    <tr>
        <td>row 1</td>
        <td><input type="button" value="move up" class="move up" /></td>
        <td><input type="button" value="move down" class="move down" /></td>
    </tr>
    ...
</table>

$('#mytable input.move').click(function() {
    var row = $(this).closest('tr');
    if ($(this).hasClass('up'))
        row.prev().before(row);
    else
        row.next().after(row);
});
Run Code Online (Sandbox Code Playgroud)

看看它在这里工作.

你也可以尝试jQuery的可排序,它更容易.