使用 .trigger() 进行 jQuery UI 拖放
我试图在没有鼠标/用户交互的情况下手动“触发”拖放。
到目前为止,我已经能够设置 jQuery UI demo 进行拖放,但无法使用触发器触发拖放() 方法。
任何人都可以帮忙设置这个吗?
到目前为止我的代码是:
$(function() {
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
$('#draggable').trigger("drop", $('#droppable'));
});
提前致谢!
让事情变得更简单。我想要做的就是从 droppable() 之外的任何地方调用“drop”方法,但我始终需要能够指定事件和 ui 对象。
I'm trying to 'trigger' a drag and drop manually without the interaction of a mouse/user.
So far I have been able to setup the jQuery UI demo for drag and drop but unable to trigger the drag and drop using the trigger() method.
Can anyone help with setting this up?
My code so far is:
$(function() {
$( "#draggable" ).draggable();
$( "#droppable" ).droppable({
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
$('#draggable').trigger("drop", $('#droppable'));
});
Thanks in advance!
To make things simpler. All I want to be able to do is call the 'drop' method from anywhere outside of the droppable() but I will always need to be able to specify the event and ui objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不创建一个由放置触发的自定义事件?所以你可以自己触发它:
Why not to create a custom event trigered by the drop? So you can trigger it yourself:
我认为你想要的是:
但即便如此,我想知道可拖动元素是否会像掉落的一样进入可放置元素......
I think what you want is:
But even then, I wonder if the draggable element will make its way to the droppable as what got dropped...