通过insertBefore实现insertAfter

function insertAfter(newElement,targetElement){
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	}else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

你可能感兴趣的:(JavaScript)