Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
Javascript jquery sortable()完整回调函数_Javascript_Jquery_Jquery Ui - Fatal编程技术网

Javascript jquery sortable()完整回调函数

Javascript jquery sortable()完整回调函数,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我有一个表,有两列-行号和名称 该表必须按用户进行排序(使用拖放) 以下是表格的html: <table class="table table-striped sorted_table"> <thead> <tr> <th>#</th> <th>Name</th> </tr> </th

我有一个表,有两列-行号和名称

该表必须按用户进行排序(使用拖放)

以下是表格的html:

<table class="table table-striped sorted_table">
        <thead>
        <tr>
            <th>#</th>
            <th>Name</th>
        </tr>
        </thead>
        <tbody id="tbody-list">
            <tr>
                <td class='td-index'>1</td>
                <td>Frank</td>
            </tr>
            <tr>
                <td class='td-index'>2</td>
                <td>Bill</td>
            </tr>
            <tr>
                <td class='td-index'>3</td>
                <td>John</td>
            </tr>
            <tr>
                <td class='td-index'>4</td>
                <td>David</td>
            </tr>
            <tr>
                <td class='td-index'>5</td>
                <td>Elisa</td>
            </tr>
            <tr>
                <td class='td-index'>6</td>
                <td>Anna</td>
            </tr>
        </tbody>
    </table>

#
名称
1.
直率的
2.
比尔
3.
约翰
4.
大卫
5.
酶联免疫吸附
6.
安娜
以下是用于排序(拖放)的jquery:

$('.sorted_table')。sortable({
containerSelector:'表',
itemPath:“>tbody”,
itemSelector:'tr',
占位符:“”,
更新:功能(事件、用户界面){
$('.td index')。每个(函数(索引){
索引++;
$(本).text(索引);
})
}
})
我使用了
sorting()
update
回调函数在每次排序后重新生成每行的编号,但它并没有这样做


我应该使用什么回调函数?

尝试
beforeStop
stop
而不是update

你能发布一个JSFIDLE吗?因此,这将是非常容易看到的JSFIDLE真棒的答案弗雷宾,你可以添加它作为一个答案
$('.sorted_table').sortable({
    containerSelector: 'table',
    itemPath: '> tbody',
    itemSelector: 'tr',
    placeholder: '<tr class="placeholder"/>',
    update: function( event, ui) {
        $('.td-index').each(function(index ) {
            index++;
            $(this).text(index );
        })
    }
})