2012-03-04 51 views

回答

0

id屬性不會被克隆。所以改成別的東西data-id可以解決你的問題。

檢查http://jsfiddle.net/tV4n7/96/

+0

感謝您的意見。我將如何引用javascript或jQuery中的數據ID?我仍然會使用$(this).attr('id');? – Derek 2012-03-04 19:42:06

+0

$(this).attr('data-id') – 2012-03-05 01:24:33

1
$('ul#routinefilter li').each(function() { 
    var id = $(this).attr('id'); 
}); 
+0

您有語法錯誤。缺少關閉');'。 – 2012-03-04 19:17:23

+0

@Jey Balachandran,謝謝:) – dotoree 2012-03-04 19:18:18

1

要創建具有所有的ID的數組:

var ids = []; 
$('#routinefilter li').each(function() { 
    ids.push(this.id); 
}); 

或者,也許更容易在以後使用,重視數據()

$('#routinefilter li').each(function() { 
    $(this).data('id', this.id); 
}); 

的數據屬性似乎堅持,這裏的a FIDDLE

使用數據而不是ID!

1

爲您的draggable添加回調。

$(".droptrue").draggable({ 
    snap: '#dropTargetframe', 
    connectToSortable: '#dropTargetframe', 
    helper: 'clone', 
    cursor: 'move', 
    revert: false, 
    drag: function (event, ui) { 
     var id = $(this).attr('id'); 
     console.log(id); 
    } 
});