我使用:http: //johnny.github.io/jquery-sortable/
使用此插件,您可以更改列表的顺序或表格行的顺序(这就是我的情况)。例如,用鼠标将第四行拖到第二个位置。宽度插件方法sort.sortable("serialize")您可以访问新订单。
但是如何使用sort.sortable("serialize")?
您可以在此处找到一个示例:http: //johnny.github.io/jquery-sortable/#table 我想将表格行的新顺序发送到 myurl.php。
如何使用sortable("serialize")通过$.post将新订单发送到 php 脚本?
HTML:
<table class="tablesort">
<tbody>
<tr data-id="39"><td>item 1</td></tr>
<tr data-id="37"><td>item 2</td></tr>
<tr data-id="40"><td>item 3</td></tr>
<tr data-id="61"><td>item 4</td></tr>
</tbody>
</table>
JavaScript:
// Initialize the plugin
var sort = $(".tablesort").sortable({
// After changing the order
onDrop: function ($item, container, _super) {
var myObject = sort.sortable("serialize");
// How to prepare *myObject* for sending?
$.post('myurl.php', {blah:myObject}, function(){});
});