JavaScript之appendChild、insertBefore和insertAfter:
[url]http://www.cnblogs.com/samlin/archive/2009/03/28/JavaScript-appendChild-insertBefore-insertAfter.html[/url]
[b]使用prototype来扩展HTML节点元素的insertAfter()[/b](注:ie下不适用,会报 [color=red]HTMLElement(或Node)未定义[/color]):
[url]http://snippets.dzone.com/posts/show/5179[/url]
[url]http://www.cnblogs.com/samlin/archive/2009/03/28/JavaScript-appendChild-insertBefore-insertAfter.html[/url]
[b]使用prototype来扩展HTML节点元素的insertAfter()[/b](注:ie下不适用,会报 [color=red]HTMLElement(或Node)未定义[/color]):
[url]http://snippets.dzone.com/posts/show/5179[/url]
// 一 扩展HTMLElement的prototype
HTMLElement.prototype.insertAfter = function(newNode, refNode) {
if(refNode.nextSibling) {
return this.insertBefore(newNode, refNode.nextSibling);
} else {
return this.appendChild(newNode);
}
}
// 二 扩展Node的prototype
Node.prototype.insertAfter = function(newNode, refNode) {
if(refNode.nextSibling) {
return this.insertBefore(newNode, refNode.nextSibling);
} else {
return this.appendChild(newNode);
}
}