UL li标签置顶

1.insertBefore

var lielem = document.createElement("li");

var momogrouplistUL = document.getElementById("momogrouplistUL");

//最新消息置顶
var urlength=momogrouplistUL.childNodes.length;
if(urlength==0){
momogrouplistUL.appendChild(lielem);
}else{
for (var i=0;i<=urlength;i++)
{
if (i==0)
  {
momogrouplistUL.insertBefore(lielem,momogrouplistUL.childNodes[i]);
break;
  }
}
}

2.prepend

//置顶
$("#momogrouplistUL").prepend($("#momogrouplistUL").children("#"+li标签id)); 

猜你喜欢

转载自blog.csdn.net/u014724048/article/details/77882353