2

我有一个可排序的列表,但我想禁用第一项,以便无法移动输入字段。

这是列表:

<ul id="sortable" class="connectedSortable">
    <input name="name1" class="inputfield" type="text" maxlength="30">
    <li>first sort item</li>
    <li>second sort item</li>
</ul>

和js:

$("#sortable:not(:first-child)").sortable({
            connectWith : ".connectedSortable"
        });

我试图用 :not(:first-child) 解决这个问题,但它不起作用......有人知道怎么做吗?

谢谢!

4

3 回答 3

4

这个怎么样?

$( "#sortable" ).sortable({
    items: '> li'   
});

演示

于 2012-11-07T18:28:30.083 回答
3

如果您修复您的 HTML 以便您的输入正确包装在列表项中,那么您可以尝试使用 sortables 的items 选项

$("#sortable").sortable({
    items: "> li:gt(0)", 
    connectWith: ".connectedSortable"
});​

jsFiddle 示例

于 2012-11-07T18:24:51.713 回答
1

您的 HTML 无效,因为您不能在 a<ul>中包含不在<li>'s 中的 HTML。

var _input = $("#sortable :first-child");

$('#sortable').before(_input); // move it outside of the UL
$('#sortable').sortable();

http://jsfiddle.net/nF7yW/

于 2012-11-07T18:28:42.103 回答