如何从可排序列表中拖动元素排除在外? [英] 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可排序,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屋!
查看全文