我有一个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只接受类可接受的元素.所以另外一个选择是当你的自定义事件发生时,只需应用或删除可接受的类.