我们将如何获得特定<ul>在jquery中

How will we get the id of a particular <ul> in jquery?

本文关键字:ul gt jquery lt 何获得 我们将      更新时间:2024-03-10

这是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
});

这是在循环中调用的,数据来自数据库。//身体

<ul id=coming from database> 
    <li>
            description
            id              
    </li>
</ul>

输出中有多个uls。我想检查我正在拖动的特定ul的id。Thanx。

jQuery
$('ul').each(function(){
    var ulID = $(this).attr('id');
});

这将从每个ul获得ID,然后你可以用它做你需要的事情。

你试过这个吗:

var ids = '';
$('ul').each(function(){
  ids += $(this).attr('id');
});

试试这个:

  $('ul').each(function()
        {
           var ids= $(this).attr('id'); // This is your rel value
        });