droppable in droppable

2019-07-09 02:56发布

I have this markup

<ul id="hello" class="cat">
    <ul id="a1" class="cat">
    </ul>
    <ul id="a2" class="cat">
    </ul>
</ul>

I did this thing

$("ul.cat").droppable(
{
    drop:function()
    {
        alert($(this).attr("id"));
    }
});

It always write "hello". only "hello". How can I bind droppable on childs too?

UPD: I want drop in elements in #hello's chidlren AND #hello itself. I want to determine where li was dropped.

3条回答
Ridiculous、
2楼-- · 2019-07-09 03:30

I've found the solution: #hello needs greedy:true

http://jqueryui.com/demos/droppable/#propagation

查看更多
家丑人穷心不美
3楼-- · 2019-07-09 03:35

try this:

$("ul.cat").each(function(){

  $(this).droppable(
  {
      drop:function()
      {
          alert($(this).attr("id"));
      }
  });

})

http://jsfiddle.net/maniator/HXjeQ/

查看更多
Animai°情兽
4楼-- · 2019-07-09 03:51

It will bubble up to the top UL, which you don't want droppable. Try this:

$("#hello ul.cat").droppable(
{
    drop:function()
    {
        alert($(this).attr("id"));
    }
});

here's a jsfiddle

查看更多
登录 后发表回答