在jquery中排序更改事件可排序

ily*_*tmn 2 javascript jquery

现在我正在使用jQuery库,我遇到了以下问题:如果项目,我有可排序的列表

    <html>
       <head>
         <script src="http://code.jquery.com/jquery-latest.js"></script>
         <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js>  </script>
         <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
       <script>
          $(document).ready(function(){
                jQuery(".block").sortable({
                axis: 'y'
             });
          });
      </script>

      </head>
      <body>
          <ul class="block" type="none">
               <li>1</li>
               <li>2</li>
               <li>3</li>
          </ul>
      </body>
  </html>
Run Code Online (Sandbox Code Playgroud)

所以更改顺序,我怎样才能为这个事件做听众,我的意思是,是否有任何关于订单更改事件或类似事件的监听器.

Mic*_*son 6

它就在文档中.使用changeupdate事件:

$(document).ready(function(){
    $(".block").sortable({
        axis: 'y',
        change: function(event, ui) { 
            console.log('change', event, ui); 
        },
        update: function(event, ui) {
            console.log('update', event, ui); 
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

也可以使用jQuery$不混合它们.

  • 我认为[`update`](http://jqueryui.com/demos/sortable/#event-update)也可能更适合OP的需求:`当用户停止排序并且DOM位置发生变化时,会触发此事件.`. (2认同)