如何排除在可排序列表中拖动的元素? [英] How to exclude an element from being dragged in sortable list?
本文介绍了如何排除在可排序列表中拖动的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从可排序列表中排除元素?例如,有一个类名为note"的元素,我不想想要可拖动?
How can I exclude an element from sortable list? For instance, there is an element with class name 'note' that I don't want to be draggable?
<ul class="sortable">
<li id="item_3">Item 3</li>
<li id="item_4">Item 4</li>
<li id="item_5">Item 5</li>
<p class="note">This is a note only</p>
</ul>
jquery ui sortable,jquery not
显然不起作用...
jquery ui sortable, jquery not
obviously does not work...
$(function() {
$( ".sortable:not(.note)" ).sortable(
}).disableSelection();
});
推荐答案
需要使用cancel.
You need to use cancel.
查看工作示例此处.
JS:
$(function() {
$('.sortable').sortable();
$('.sortable').disableSelection();
$('.sortable').sortable({ cancel: '.note' });
});
正如@Zephyr 指出的那样,这让您可以通过拖动兄弟姐妹来重新排列位置,如果您想避免这种情况,请使用 owise1 方法:
As @Zephyr points out, this let's you re-arrange the position by dragging the siblings, if you want to avoid that, use owise1 approach:
$('.sortable').sortable({
items : ':not(.note)'
});
这篇关于如何排除在可排序列表中拖动的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文