1
我在拖動用戶拖拽角色的拖拽操作。我知道我是如何獲取用戶ID和目標角色ID的,但我不知道如何獲取用戶被拖動到的FROM角色ID!JQuery UI:在drag'n'dop中獲取源元素的ID
<div id="role_1" class="role">
<h5>Administrator</h5>
<ul class="users">
<li id="user_1">Foo</li>
<li id="user_2">Bar</li>
</ul>
</div>
<div id="role_2" class="role">
<h5>Member</h5>
<ul class="users">
<li id="user_1337">Baz</li>
</ul>
</div>
<script type="text/javascript">
$(function() {
// Get roles and users lists
var $templates = $(".role"),
$users = $(".users");
// let the user items be draggable
$("li", $users).draggable({
revert: "invalid", // when not dropped, the item will revert back to its initial position
containment: "document",
helper: "clone",
cursor: "move"
});
// let the roles be droppable, accepting the user items
$templates.droppable({
accept: ".users > li",
activeClass: "ui-state-highlight",
drop: function(event, ui) {
var $uid = ui.draggable.attr("id"),
$targetRid = $(this).attr("id"),
$sourceRid = ???;
// snip
}
});
});
</script>
感謝您的幫助提前。
感謝那些給我我所需要的暗示......我只是做了'ui.draggable.closest(「角色」。 ).attr(「id」)'在droppable的放置事件中;) –
@ Hikaru-Shindo:啊,當然是。好一個!因爲這與我的回答截然不同,所以您可能希望將其作爲自己的答案發布,並在兩天內接受。這在這裏完全沒問題。當然,你的電話。無論如何,很高興有幫助! –