js遍历 子节点 子元素
// 添加子节点前 删除所有子节点
var usernameEle = document.getElementById("username");
var childs = usernameEle.childNodes;
for(var i = childs.length - 1; i >= 0; i--) {
usernameEle.removeChild(childs[i]);
}
var username = document.createTextNode(obj.username);
usernameEle.appendChild(username);
方法:
原文地址:http://blog.csdn.net/xiebaochun/article/details/38382785