这是jquery函数,它使ul可拖动并且特定区域可以放置。 // Jquery的
$(function () {
// there's the gallery5 and the trash
var $gallery5 = $("#gallery5"),
$trash = $("#trash");
// let the gallery5 items be draggable
$("ul", $gallery5).draggable({
cancel: "a.ui-icon", // clicking an icon 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: "#gallery > li",
accept: "#gallery2 > li",
activeClass: "ui-state-highlight",
drop: function (event, ui) {
alert("trash");
deleteImage(ui.draggable);
}
});
// let the gallery be droppable as well, accepting items from the trash
$gallery5.droppable({
accept: "#gallery li , #gallery2 li , #gallery4 li , #gallery3 li",
activeClass: "custom-state-active",
drop: function (event, ui) {
alert("gallery5");
recycleImage(ui.draggable);
}
});
// image deletion function
var recycle_icon = "<a href='link/to/recycle/script/when/we/have/js/off' title='Recycle this image' class='ui-icon ui-icon-refresh'>Recycle image</a>";
// image recycle function
var trash_icon = "<a href='link/to/trash/script/when/we/have/js/off' title='Delete this image' class='ui-icon ui-icon-trash'>Delete image</a>";
function recycleImage ($item) {
// alert("recycleImage");
$item.fadeOut(function () {
$item
.find("a.ui-icon-refresh")
.remove()
.end()
.css("width", "250px")
.find("img")
.css("height", "50px")
.end()
.fadeIn()
.appendTo($gallery5);
});
}
// image preview function, demonstrating the ui.dialog used as a modal window
});
这是在循环中调用的,数据来自数据库。 // BODY
<ul id=coming from database>
<li>
description
id
</li>
</ul>
输出中有多个uls。我想检查我拖动的特定ul的id。 感谢名单。
答案 0 :(得分:1)
的jQuery
$('ul').each(function(){
var ulID = $(this).attr('id');
});
这将获得每个ul的ID,然后您可以随意使用它。 。
答案 1 :(得分:0)
你有没有试过这个:
var ids = '';
$('ul').each(function(){
ids += $(this).attr('id');
});
答案 2 :(得分:0)
试试这个:
$('ul').each(function()
{
var ids= $(this).attr('id'); // This is your rel value
});