jQuery UI 可排序表句柄

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4471520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:19:13  来源:igfitidea点击:

jQuery UI sortable table handle

jqueryjquery-uijquery-ui-sortable

提问by Diego

I'm having some difficults with sortable option handle.

我在可排序选项句柄方面遇到了一些困难。

When I use:

当我使用:

$("table tr").sortable().disableSelection();

There is no problem.

没有问题。

If I add the handle option then the sortable stops working:

如果我添加 handle 选项,则 sortable 停止工作:

$("table tr").sortable({
    handle: "td:eq(0)"
}).disableSelection();

The links:

链接:

http://jsfiddle.net/22C2n/

http://jsfiddle.net/22C2n/

http://jsfiddle.net/22C2n/1/

http://jsfiddle.net/22C2n/1/

Can anyone help me please?

有人可以帮我吗?

回答by mike

Wrap your <tr>'s in a <tbody>and change your code to:

将您的<tr>'s包裹在 a 中<tbody>并将您的代码更改为:

$("table tbody").sortable({
    handle: 'td:first'
}).disableSelection();

You specify the container that contains the elements you want to be sortable not the actual elements...

您指定包含要排序的元素而不是实际元素的容器...

回答by Reto Aebersold

Try to pass an element: http://jsfiddle.net/22C2n/5/

尝试传递一个元素:http: //jsfiddle.net/22C2n/5/

$("table tr").sortable({
    handle: $("td:eq(0)")
}).disableSelection();

回答by Mottie

Setting the handle to td:eq(0)makes only the first table cell sortable, all the rest of the cells are not. Try adding a spaninside the tdand use it as the handle (demo).

将句柄设置为td:eq(0)仅使第一个表格单元格可排序,所有其余单元格均不可排序。尝试在span里面添加一个td并将其用作句柄(演示)。

HTML

HTML

<table>
    <tr>
        <td><span>&bull;</span>1A</td>
        <td>1B</td>
        <td>1C</td>
    </tr>
    ...
</table>

Script

脚本

$("table tr").sortable({
    handle: "span"
}).disableSelection();