Get the order of list item in jquery sortable

后端 未结 5 651
后悔当初
后悔当初 2021-02-04 12:34

I have done this http://jsbin.com/UBezOVA/1/edit.

When I click the submit button, i want to get the current order of the list item. But, it seems that $(\"#sortab

5条回答
  •  广开言路
    2021-02-04 13:19

    gaurav is on the right track, but as purefusion mentioned "id attributes are always supposed to start with an alpha character"

    Accordingly, The html valid approach is to add data attributes

    var idsInOrder = $("#sortable2").sortable('toArray', {attribute: 'data-id'});
    

    $(document).ready(function() {
    
      var idsInOrder = $("#sortable2").sortable('toArray', {
        attribute: 'data-id'
      });
    
    
      alert(idsInOrder);
    
    });
    
    
    
    
    
    
    • Item 1
    • Item 2
    • Item 3
    • Item 4
    • Item 5

提交回复
热议问题