Jquery 取消拖动可排序项目
一种绝对常见的可排序情况:Jquery 取消拖动可排序项目,jquery,jquery-ui,jquery-ui-sortable,Jquery,Jquery Ui,Jquery Ui Sortable,一种绝对常见的可排序情况: <script> $(function() { $("#sortable").sortable(); }); </script> <ul id="sortable"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> 将非常有助于提供建议。排序函数回调对排序的作用与拖动拖动
<script>
$(function() {
$("#sortable").sortable();
});
</script>
<ul id="sortable">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
将非常有助于提供建议。排序函数回调对排序的作用与拖动拖动的作用相同(): Sortable具有使用
Sortable('cancel')
调用的“取消”功能
在文档中:“取消当前排序表中的更改,并将其恢复到当前排序开始之前的状态。”请参阅
用法示例:
$("#sortable").sortable({
stop: function(e, ui) {
if ("I need to cancel this") {
$(ui.sender).sortable('cancel');
}
}
});
按建议返回
false
对于使事物动态不可排序非常有用,但在可排序配置中也有一个允许您设置静态不可排序:
$("#sortable").sortable({
// this prevents all buttons, form fields, and elemens
// with the "unsortable" class from being dragged
cancel: ":input, button, .unsortable"
});
试一试
$('#列表1')。可排序({
连接到:“ul”
});
$('#list2')。可排序({
连接到:'ul',
接收:功能(ev、ui){
if(ui.item.hasClass(“编号”))
ui.sender.sortable(“取消”);
}
});
这会引发一个错误:“Uncaught TypeError:无法读取null的属性“0”我还获取了该错误错误:“Uncaught TypeError:无法读取null的属性“0”,但您的答案不正确。。因为我的返回值为false,所以我的拖动项目禁用,第二次不拖动
ui。这里不能使用sender
,因为sender
是项目从一个可排序表移动到另一个可排序表时的可排序表()。如果您想要单个排序,请使用$(this).sortable('cancel')
super-awesome。。这花了半天时间,在一天结束时,答案是非常好的实现,基于类名,就像我需要的那样。请注意,在应用了cancel CSS类的元素下面的任何嵌套排序表(例如,在嵌套树视图中)也将被禁用排序,即使它们没有应用该类。
$("#sortable").sortable({
stop: function(e, ui) {
if ("I need to cancel this") {
$(ui.sender).sortable('cancel');
}
}
});
$("#sortable").sortable({
// this prevents all buttons, form fields, and elemens
// with the "unsortable" class from being dragged
cancel: ":input, button, .unsortable"
});
$('#list1').sortable({
connectWith: 'ul'
});
$('#list2').sortable({
connectWith: 'ul',
receive: function(ev, ui) {
if(ui.item.hasClass("number"))
ui.sender.sortable("cancel");
}
});