首页 > Web开发 > 详细

js 实现insertAfter

时间:2015-06-07 20:14:58      阅读:283      评论:0      收藏:0      [点我收藏+]

 

function insertAfter(ele,html){
    var new_ele = document.createElement("div");
    new_ele.innerHTML = html;
    var parent = ele.parentNode || document.body;
    parent.insertBefore(new_ele.firstChild, ele.nextSibling);
}

var d = document.getElementById("test");
insertAfter(d,"<div>dddddddd</div>")

 

var d = document.getElementById("test");
d.childNodes;//...
d.previousSibling;//null
d.nextSibling;//null
d.parentNode;//body
d.firstChild;//a
d.lastChild;//b
d.lastChild.textContent;//b
d.lastChild.previousSibling.innerHTML;//Item4

 

js 实现insertAfter

原文:http://www.cnblogs.com/eturn/p/4558925.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!