2011-11-08 48 views

回答

11

使用jQuery你可以尝试选择sortables和考多少元素返回:

if ($('.sortable-class').length > 0) {/*something with the class `sortable-class` exists*/} 

上面的代码假定每个在你的排序元素有类sortable-class。你真正需要的是一个唯一的选择器,它只能找到你的排序。举例来说,如果您的sortables是元素的所有孩子那么你的选择看起来是这样的:

HTML

<ul id="sortable_parent"> 
    <li>this is sortable</li> 
    <li>this is also sortable</li> 
</ul> 

JS

if ($('#sortable_parent').children('li').length > 0) {/*atleast one li exists*/} 

这里的一些文件,如果你进入的是一种东西:http://api.jquery.com/length

+0

这工作完美!谢谢。 –