如何排除元素在可排序列表中被拖动?

如何从可排序列表中排除元素? 例如,有一个类名为’note’的元素,我不想被拖动

  • Item 3
  • Item 4
  • Item 5
  • This is a note only

jquery ui sortable,jquery显然不起作用…

 $(function() { $( ".sortable:not(.note)" ).sortable( }).disableSelection(); }); 

你需要使用取消。

请参阅此处的工作示例

JS:

 $(function() { $('.sortable').sortable(); $('.sortable').disableSelection(); $('.sortable').sortable({ cancel: '.note' }); });​ 

正如@Zephyr指出的那样,让你通过拖动兄弟姐妹来重新安排位置,如果你想避免这种情况,请使用owise1方法 :

 $('.sortable').sortable({ items : ':not(.note)' }); 

您可以使用sortable的“ items ”选项:

 $( ".sortable" ).sortable({ items : 'li' }); 

要么…

 $( ".sortable" ).sortable({ items : ':not(.note)' }); 

您可以使用以下内容明确排除项

 $( ".sortable" ).sortable({ cancel: ".disable-sorting" });