【问题标题】:droppable in droppabledroppable 中的 droppable
【发布时间】:2011-03-31 18:59:44
【问题描述】:

我有这个标记

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

我做了这件事

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

它总是写“你好”。 只有“你好”。 我如何也可以在孩子上绑定 droppable?

UPD:我想在#hello's chidlren 和#hello 本身中加入元素。我想确定 li 被丢弃的位置。

【问题讨论】:

  • 你能发布你的代码的 JSFiddle 示例吗?
  • 我已经修复了 html 标记。如果未标记为“代码”,则 Stackoverflow 默认不显示 html
  • ul 元素里面有什么?
  • 没关系 会有"li"从其他容器拖过来

标签: jquery jquery-ui droppable


【解决方案1】:

我找到了解决方案:#hello 需要 greedy:true

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

【讨论】:

    【解决方案2】:

    它会冒泡到您不希望丢弃的顶部 UL。试试这个:

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

    here's a jsfiddle

    【讨论】:

    • 谢谢你的小提琴。那么 ul.cat 中的 ul.cat 中的 ul.cat 呢?我想防止冒泡
    • 我想加入#hello
    【解决方案3】:

    试试这个:

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

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

    【讨论】:

    • 冒泡时仍会提示“你好”。
    • @rsplak 我也修复了 html
    猜你喜欢
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2014-04-06
    • 1970-01-01
    相关资源
    最近更新 更多