Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

javascript - How do I trigger the Drop event with jQuery UI Droppable without actually dragging and dropping?

I have a droppable with a drop event handler:

$(this).droppable({
  drop:function(){
    console.log('OMG You Dropped It!');
  }
});

I have a draggable:

$(this).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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...