Discuss / JavaScript / 练习,直接对获取的li排序

练习,直接对获取的li排序

Topic source

var ul = $('#test-div>ul');

ul.append('<li><span>Pascal</span></li>')

ul.append('<li><span>Lua</span></li>')

ul.append('<li><span>Ruby</span></li>')

var li = $('#test-div>ul>li');

li.sort((x,y)=>x.innerText>y.innerText?1:-1);

$('#test-div>ul>li').remove();

 ul.append(li);

18thhell

#2 Created at ... [Delete] [Delete and Lock User]

remove没啥意义。

如果要添加的DOM节点已经存在于HTML文档中,它会首先从文档移除,然后再添加,也就是说,用append(),你可以移动一个DOM节点。


  • 1

Reply