我有下面的示例表代码,
<table id="Table1">
<thead>
<th>Title</th>
</thead>
<tbody>
<tr>
<td>Row 1</td>
</tr>
<tr>
<td>Row 2</td>
</tr>
<tr>
<td>Row 3</td>
</tr>
<tr class='disabled'>
<td>Row 4</td>
</tr>
<tr>
<td>Row 5</td>
</tr>
</tbody>
</table>
我正在下面应用 jQuery Sortable,效果很好,
$("#Table1 tbody").sortable({
});
但是,现在我想排除具有“disabled”类的“tr”的可排序,为此我应用了下面的代码(jquery 选择器),但它不起作用。选择器有什么问题吗?我必须在 HTML 表格中使用“thead”和“tbody”。
或者有什么替代方法吗?谢谢,
$("#Table1 tbody tr:not(.disabled)").sortable({
});
最佳答案
使用items
选项:
Specify which items are eligible to sort by passing a jQuery selector into the items option. Items excluded from this option are not sortable, nor are they valid targets for sortable items.
$("#Table1 tbody").sortable({
items: 'tr:not(.disabled)'
});
Demo
关于jquery - 从可排序中排除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17104842/