我正在寻找一种方法来触发事件从恢复状态,如果某些事情没有验证,例如,如果元素存在,它将从另一个列表创建它,但如果它已经存在,它应该转到else并将元素返回到它原来的位置:
$( "#catalog ul" ).droppable({ tolerance: 'fit',activeClass: "ui-state-default",hoverClass: "ui-state-hover",accept: ":not(.ui-sortable-helper)",drop: function( event,ui ) { //check if already exists if($(this).find("#"+$(ui.draggable).attr("id")).length==0){ $( "<li id="+$(ui.draggable).attr("id")+"></li>" ).text( ui.draggable.text() ).appendTo( this ) .draggable({ revert: 'invalid',stop: function(){ $(this).draggable('option','revert','invalid'); } }).droppable({ greedy: true,tolerance: 'touch',drop: function(event,ui){ ui.draggable.draggable('option',true); } }); }else{ //want to make the object go back by setting true to revert return false; } } })
@R_403_323@
谢谢Kenji,这确实有效:
ui.draggable.draggable('option',true);
我一直在努力争取一个早上,直到找到你的帖子,谢谢