jQuery排序取消事件(如果无效) [英] jQuery sortable cancel event if not valid
本文介绍了jQuery排序取消事件(如果无效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可排序的列表.在开始排序之前,我想检查该列表中的所有元素是否有效.如果不是,请取消该事件并保留列表不变.
I have a list which is sortable. Before I start sorting, I want to check if all the elements of that list are valid. If not, cancel the event and leave the list intact.
您可以在此处找到代码 http://jsfiddle.net/DZYW5/4/
You can find the code here http://jsfiddle.net/DZYW5/4/
当我使用它时,事件被取消,但是元素被删除了.
When I use this, the event is canceled, but the element is removed.
start: function (event, ui) {
if (!valid()) {
return false;
// it cancel's but the element is removed...
}
}
也许我应该实现一个"beforeStart"事件?有什么建议吗?
Maybe I should implement a "beforeStart" event? Suggestions?
推荐答案
您可以使用取消方法
$("#list").sortable({
connectWith: ".connectedSortable",
items: '.sortable-item',
handle: '.handle',
placeholder: "ui-state-highlight",
stop: function (event, ui) {
console.log('stop')
if (!valid()) {
$( this ).sortable( "cancel" );
}
}
});
演示:小提琴
这篇关于jQuery排序取消事件(如果无效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文