我有一個可拖動列表(.field),您可以在其中拖放&刪除項目到可排序列表(.sortlist)中。我這樣做是因爲我不希望主列表(.field)以任何方式改變。它工作正常,除了我不能解決如何操縱可排序列表中的拖放字段。jQuery - 操縱可排序列表中的丟棄元素
我可以用一個函數下面從一個可拖動做它變成一個可投放區域「下拉:」在投擲的():
$(this).append('html code here to change content of dragged field');
然而,這並不內部的排序工作() 。我的代碼如下所示:
$(".sortlist").sortable({
receive: function(event, ui) {
var dropElemTxt = $(ui.item).text();
var dropElemId = $(ui.item).attr('id');
$(ui.item).replaceWith('<li class="box" id="'+dropElemId+'">Updated field! '+dropElemTxt+'</li>');
}
});
$(ui.item).replaceWith改變正被拖到主場,所以這是行不通的。我嘗試了$(this).replaceWith,但更新了可排序區域(.sortlist)。
任何想法我需要什麼代碼引用被拖動的項目?
非常感謝, 阿里。
*幾年後* – Petah 2014-12-08 09:54:46