开发者

jQuery : Append child + sortable

I need to sort some li's but I don't know how to add a children to an empty li. At this moment I can add li's to another li only if is not empty.

EG.

<ul>
     <li id="1">Item开发者_Go百科</li>
     <li id="2">Item
         <ul>
            <li id="3">Item</li>
            <li id="4">Item</li>
         </ul>
     </li>
     <li id="5">Item</li>
     <li id="6">Item</li>
</ul>

So I can add li_1 into li_2 but I can't add li_6 into li_5 because li_5 is empty.

My work can be found here.


A simple solution is to add empty ul with an padding / margin than you can drop the items into this empty sublist. http://jsfiddle.net/k83QH/2/


One way to get around this would be to add an empty ul, in jQuery, to any list items that could potential have children dragged into them. That way you'll get the drop container for all of your li's


You will have to check whether there is any ul child element for that li, if not, then add a ul element, and then add your child li elements in it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜