droppable in droppable

*爱你&永不变心* 提交于 2019-12-24 00:15:33

问题


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.


回答1:


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

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




回答2:


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




回答3:


try this:

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

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

})

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



来源:https://stackoverflow.com/questions/5504888/droppable-in-droppable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!