这是我的代码来自http://jsfiddle.net/XUFUQ/1/
$(document).ready(function()
{
addElements();
}
);
function addElements()
{
$("#list1").empty().append(
"<li id='item1' class='list1Items'>Item 1</li>"+
"<li id='item2' class='list1Items'>Item 2</li>"+
"<li id='item3' class='list1Items'>Item 3</li>"
);
}
$(function() {
// there's the gallery and the trash
var $gallery = $( "#list1" ),
$trash = $( "#list2" );
// let the gallery items be draggable
$( "li", $gallery ).draggable({
cancel: "button", // these elements won't initiate dragging
revert: "invalid", // when not dropped, the item will revert back to its initial position
containment: "document",
helper: "clone",
cursor: "move"
});
// let the trash be droppable, accepting the gallery items
$trash.droppable({
accept: "#list1 > li",
drop: function( event, ui ) {
$("#list2").append(ui.draggable);
addElements();
}
});
});
在文档就绪方法中,我将一些元素附加到 list1,然后我在该列表上初始化可拖动,因此我第一次能够拖动 list1 元素。在放入 list2 时,我正在调用 addElements() 函数来清除并将一些元素添加到 list1。但我无法拖动这些添加的元素。
如何使这些元素可拖动?