如何在不实际拖放的情况下使用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 上的放置事件处理程序没有实际拖放可拖动。我想在没有实际行为的情况下模拟实际行为。
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屋!