2011-05-13 53 views
6

我有一個jQuery UI可排序功能的工作示例。我將它應用到HTML表格來拖放和排列表格行。除了我想排除某些行的排序以外,它的效果很好。使用items參數,我可以成功地排除ONE類("list-button-bar"類),但是我不能爲我的生活弄清楚如何排除多個類的語法。例如,我想排除<th>和其他類<tr>jQuery UI可排序 - 如何包含/排除多個「項目」?

這可能是文檔中的那些之一,但我對jQuery UI還不夠熟悉,甚至不知道要搜索什麼。

這裏的工作代碼:

<script> 
    $(function() { 
     $("#applications_list tbody.list-tbody").sortable({ 
     items: "tr:not(.list-button-bar)", 
     cursor: 'crosshair' 
     }); 
     $("#applications_list tbody.list-tbody").disableSelection(); 

    }); 
</script> 

回答

14

您是否嘗試過使用逗號?該items選項接受一個jQuery選擇:

$("#applications_list tbody.list-tbody").sortable({ 
    items: "tr:not(.list-button-bar), :not(th)", // Excludes <tr>s without a class and <th>s 
    cursor: 'crosshair' 
    }); 
+0

謝謝。 「jQuery選擇器」 - 這是我需要的魔術關鍵字!一旦我知道我在找什麼,這很容易找到。這個文檔解釋得非常好(實際上它比新版本的文檔更好解釋,這對於新手來說是完全不友好的)http://docs.jquery.com/DOM/Traversing/Selectors 最後,我發現只要包含的我想要使用的項目更容易:「tr:.even,.odd」, 有一件事完全是不幸的巧合,我的表單有類「偶」和「奇」 ,它們是選擇器關鍵字。在前面添加點解決了這一點。 – TrojanName 2011-05-16 08:09:43

+0

@布萊恩:啊,好的。那麼我很高興我可以幫助:) – 2011-05-16 19:38:43

1

在jQuery UI的1.8使用以下命令:

$("#applications_list tbody.list-tbody").sortable({ 
    // Excludes <tr>s without a class and <th>s 
    filter: "tr:not(.list-button-bar), :not(th)" 
}); 
+1

好的方法,我喜歡! – TrojanName 2011-06-21 10:14:47

2

要排除多個類別TR使用:

$("#applications_list tbody.list-tbody").sortable({ 
     items: "tr:not(.list-button-bar,.other-class1,.other-class2)", 
     cursor: 'crosshair' 
});