手写js的insertAfter
function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if(parent.lastChild == targetElement){ parent.appendChild(newElement); }else{ parent.insertBefore(newElement,targetElement.nextSibling); } }
还有这个下移的实现
function down(){ var liCurrent = this.parentNode.parentNode; var next = liCurrent.nextSibling; while(next){ if(next.nodeName == 'LI'){ break; } next = next.nextSibling; } if(next) { insertAfter(liCurrent,next); } else { alert('已经是最后一个了'); } }