我有一个jQuery UI Sortable函数的工作示例。我正在将它应用于HTML表来拖放和排序表行。它工作得很好,除了我想排除某些类的行是可排序的。使用items
参数,我可以成功排除一个类("list-button-bar"
类),但我不能为我的生活找出如何排除多个类的语法。例如,我想要排除<th>
和其他类<tr>
。
这可能是文档中的其中一个,但我还不熟悉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>
答案 0 :(得分: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'
});
答案 1 :(得分:2)
要排除多个tr使用类:
$("#applications_list tbody.list-tbody").sortable({
items: "tr:not(.list-button-bar,.other-class1,.other-class2)",
cursor: 'crosshair'
});
答案 2 :(得分: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)"
});