jquery-ui – 如何取消jQuery droppable的drop action?

我有一个jQuery UI droppable接受draggables.如果满足某些条件,我想不允许放行.

如何取消放弃操作并执行还原操作?

解决方法

可插拔小部件上的 accept选项:

All draggables that match the selector
will be accepted. If a function is
specified,the function will be called
for each draggable on the page (passed
as the first argument to the
function),to provide a custom filter.
The function should return true if the
draggable should be accepted.

结合revert选项在draggable应该得到你所需要的:

$(".draggable").draggable({
    revert: 'invalid'
});

$("#droppable").droppable({
    accept: function(el) {
        /* This is a filter function,you can perform logic here 
           depending on the element being filtered: */
        return el.hasClass('acceptable');
    }
});

请注意,在这个具体的例子中,你也可以写接受:“.acceptable”,这将使得droppable只接受类可接受的元素.所以另外一个选择是当你的自定义事件发生时,只需应用或删除可接受的类.

这里有一个例子:http://jsfiddle.net/andrewwhitaker/rUgJF/3/

底部一个链接切换“可接受性”关闭.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...