关于父子问题的jquery ui droppable [英] jquery ui droppable on parent child issue

查看:73
本文介绍了关于父子问题的jquery ui droppable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery ui droppable小部件。我有以下结构:

I am using jquery ui droppable widget. I have the following structure :

示例小提琴

 <div class="parent">
    parent
   <div class="child">
     child
   </div>
  </div>

父元素和子元素都可以删除,并且两者都接受相同的项目。我的问题是当我在子项上删除元素而不是父项删除事件正在执行时(请检查小提琴)。我该如何阻止这种行为?

Both parent and child elements are droppable and both are accepting the same item. My issue is when i am dropping the element on child than also parent drop event is executing ( please check the fiddle ). How can i stop this behaviour ?

推荐答案

我想更好的方法是使用droppable的贪婪选项。如果您发现任何问题,请不要忘记浏览API。 http://api.jqueryui.com/droppable/#option-greedy

I guess the better way is to use greedy option of droppable. Don't forget to go through the API if you find any problem. http://api.jqueryui.com/droppable/#option-greedy

以下是贪婪选项代码的样子

Here is how your code looks like with greedy option


$(".child").droppable({ 
    accept: '.item',
    greedy: true,
    drop: function(e, ui){ 
     alert("drop on child");
    }
});

你去...... !!!

There you go... !!!

这篇关于关于父子问题的jquery ui droppable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆