[英]How will we get the id of a particular <ul> in jquery?
This is the jquery function which makes the ul draggable and and a particular area droppable. 这是使ul可拖动并且可拖放特定区域的jquery函数。 //Jquery // 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
});
This is called in a loop and the data is coming from the database. 这被称为循环,并且数据来自数据库。 //BODY //身体
<ul id=coming from database>
<li>
description
id
</li>
</ul>
There are multiple uls in the output. 输出中有多个ul。 I want to check the id of that particular ul which i am dragging. 我想检查我拖动的特定ul的ID。 Thanx. 感谢名单。
jQuery jQuery的
$('ul').each(function(){
var ulID = $(this).attr('id');
});
This will get the ID from each ul, you can then do what you need with it . 这将从每个ul获取ID,然后您就可以使用它进行所需的操作。 . 。 . 。
Have you ever try this: 您是否尝试过:
var ids = '';
$('ul').each(function(){
ids += $(this).attr('id');
});
Try this: 尝试这个:
$('ul').each(function()
{
var ids= $(this).attr('id'); // This is your rel value
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.