如何在不实际拖放的情况下使用 jQuery UI Droppable 触发 Drop 事件? [英] How do I trigger the Drop event with jQuery UI Droppable without actually dragging and dropping?
问题描述
我有一个带有放置事件处理程序的 droppable:
I have a droppable with a drop event handler:
$(this).droppable({
drop:function(){
console.log('OMG You Dropped It!');
}
});
我有一个可拖动:
$(this).draggable();
我想要做的是在 droppable 上触发放置事件处理程序,而无需实际拖放 draggable.我想在不实际执行行为的情况下模拟实际行为.
What I want to do is trigger the drop event handler on the droppable without actually dragging and dropping the draggable. I want to simulate the actual behavior without physically performing the behavior.
我认为这样的事情会做:
I thought something like this would do:
$(droppable).trigger('drop', [draggable]);
不幸的是,事情并没有那么简单.有谁知道我如何才能做到这一点?
Unfortunately, it's not quite that simple. Does anyone know how I can accomplish this?
推荐答案
您应该将 drop
处理程序中的代码移动到单独的函数中.
然后,您可以在处理程序和其他地方调用该函数.
You should move the code in your drop
handler to a separate function.
You can then call the function both in the handler and elsewhere.
这篇关于如何在不实际拖放的情况下使用 jQuery UI Droppable 触发 Drop 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!