2016-08-28 2 views
0

私はjQueryソート可能です。私は移動したアイテムのIDとそれが置き換えたアイテムのIDを取得できるようにしたい。これまでは、移動した要素のIDは取得できましたが、置き換えられた要素は取得できませんでした。jqueryで移動したIDと置き換えられたIDを取得する方法

私のコードは次のとおりです。

$(function() { 
    $("#sortable").sortable({ 
     stop: function (event, ui) { 
      var moved = ui.item, 
       replaced = ui.item.prev(); 

      // if replaced.length === 0 then the item has been pushed to the top of the list 
      // in this case we need the .next() sibling 
      if (replaced.length == 0) { 
       replaced = ui.item.next(); 
      } 

      alert("moved ID:" + moved.attr("id"), "replaced ID:" + replaced.attr("id")); 
     } 
    }); 
}); 

どのように私は戻って交換される要素のためのIDと移動された要素の両方を得るのですか?

jsFiddle

答えて

3

実はそれはあなただけで間違った引数を使ってアラートを呼び出している、動作します。 console.logとそれを交換するか、このような文字列を連結する:

alert("moved ID:" + moved.attr("id") + "replaced ID:" + replaced.attr("id")); 

(私は+,を置き換え)

+0

うわー、おかげでたくさんのダリオ。 – kevinabraham

関連する問題