jquery – 从可排序项中排除项目

前端之家收集整理的这篇文章主要介绍了jquery – 从可排序项中排除项目前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下示例表代码,
<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({
});

但是,现在我想排除类别为“禁用”的“tr”排序,我要应用下面的代码(jquery选择器),但它不起作用.选择器有什么问题吗?我必须在HTML表格中使用“thead”和“tbody”.

或者有其他方法吗?谢谢,

$("#Table1 tbody tr:not(.disabled)").sortable({
});

解决方法

使用 items选项: @H_403_18@

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

原文链接:https://www.f2er.com/jquery/176583.html

猜你在找的jQuery相关文章