如何在不实际拖放的情况下使用jQuery UI Droppable触发Drop事件? [英] How do I trigger the Drop event with jQuery UI Droppable without actually dragging and dropping?

查看:179
本文介绍了如何在不实际拖放的情况下使用jQuery UI Droppable触发Drop事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有放置事件处理程序的 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屋!

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