1

What is the easiest way to count of ui sortable elements?

<ul id="sortableList">
  <li class="nosort"></li>
  <li>item 1<li>
  <li>item 2<li>
  <li class="nosort"></li>
  <li>item 3<li>
</ul>

Since i have already performed DOM elemens selection
(>:not(.nosort)) in options of sortable function

$("#sortableList").sortable({
    items: ">:not(.nosort)"

may i use ui.item somehow to count?

4

2 回答 2

1
alert($('#sortableList li').not('.nosort').length);

警告没有类的li元素计数#sortableList.nosort

于 2012-12-18T16:20:39.487 回答
1

您可以只使用 .length ,因为 jQuery 返回一个包含所选项目的数组:

$('#sortableList li:not(.nosort)').length
于 2012-12-18T16:21:19.397 回答