Discuss / JavaScript / 签到

签到

Topic source

断桥-过后

#1 Created at ... [Delete] [Delete and Lock User]
var box=$('#test-div ul'),
    newList=['Pascal','Lua','Ruby'],
    newListHtml,
    a,b,li;
for(let i=0;i<newList.length;i++){
    newListHtml+='<li><span>'+newList[i]+'</span></li>';
}
box.append(newListHtml);
li=box.find('li');
li.sort((x,y)=>{
    a=$(x).text().toUpperCase();
    b=$(y).text().toUpperCase();
    if(a<b){
        return -1;
    }else if(a==b){
        return 0;
    }else{
        return 1;
    }
});
box.append(li);

  • 1

Reply