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
jQuery UI sortable table handle
提问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:
链接:
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 span
inside the td
and use it as the handle (demo).
将句柄设置为td:eq(0)
仅使第一个表格单元格可排序,所有其余单元格均不可排序。尝试在span
里面添加一个td
并将其用作句柄(演示)。
HTML
HTML
<table>
<tr>
<td><span>•</span>1A</td>
<td>1B</td>
<td>1C</td>
</tr>
...
</table>
Script
脚本
$("table tr").sortable({
handle: "span"
}).disableSelection();