如何获得拖动元素的ID并在删除时绑定?

嗨所有我怎么能得到拖动元素的Id和绑定我在哪里删除元素的ID是我正在为我的拖放做什么

var i = 1; var z = 1; $(document).ready(function () { $("button[id='columnadd']").click(function () { // create the element var domElement = $('

Add Menu Items Here

'); var holder = "#columnholder"; $("#columnholder").append(domElement); //$(this).after(domElement); // at this point you have domElement in your page // make it droppable domElement.find("ol").droppable({ activeClass: "ui-state-default", accept: '.small_box li', greedy: true, drop: function (event, ui) { makeItDroppableToo(event, ui, this); } }); }); function makeItDroppableToo(e, ui, obj) { $(obj).find(".placeholder").remove(); var id = this.id; alert(id); var placeholder = $("
  1. Add Sub Menu here
"); $("
  • ").append('' + ui.draggable.text() + '').append(placeholder).appendTo($(obj)); // this is the same as the previous one placeholder.droppable({ greedy: true, // put options here drop: function (event, ui) { makeItDroppableToo(event, ui, this); } }); } $(".small_box li" ).draggable({ appendTo: "body", helper: "clone" }); });

    这是我从我拖动的地方的html

      
    Menu Builder

    在这里我将拖动元素,当我这样做,我想得到id,当我绑定拖动元素在这里

      $("
  • ").append('' + ui.draggable.text() + '').append(placeholder).appendTo($(obj));

    我想将该id绑定到,任何人都可以告诉我该怎么做

    在drop handler中,你可以使用ui.draggable.attr('id')来获取被拖动元素的id。

     ... drop: function(ev, ui) { /* // get id of dragged element var draggedID = ui.draggable.attr('id'); // bind it #('#'+draggedID).bind(...); // bind your events here */ // why get the id, when you can bind it directly // will work with elements without an id too (credit to Rory McCrossan) ui.draggable.bind(...); }, ...