的
作用是:定义
appendChild(newchild:节点的节点):
添加一个节点到节点的子节点阵列。
支持:IE 5 +,Mozilla 1 +,网景6 +,Safari 1 +,Opera 7 +
将节点添加到数组指定节点的子节点中,读起来就像一口,只需将元素添加到指定的节点即可。
appendChild用法
target.appendchild(newchild)
插入的最后一个子节点为
目标的孩子后newchild
榜样的作用是:
VaR新元素= document.document.createelement('label);
newelement.element.setattribute(币值,'username:');
Var usernameText = document.Document.getElementById ('username');
usernametext.appendchild(
空间);
在定义
insertBefore()
方法的一个现有的孩子之前插入一个新的子节点
在的作用()方法是在现有的子节点插入一个新的子节点
在使用
target.insertbefore(newchild,existingchild)
newchild插在existingchild节点作为目标的孩子
existingchild可选
参数,当它是空的,效果是相同的作用是:
在示例
VaR的抗议= document.getelementbyid(测试);
无功节点= document.createelement(P);
newnode.innerhtml =这是一个测试;
otest.insertbefore(节点、子节点的抗议。{ 0 });
好的,那么应该有一个都在用,对吧
好吧,让我们用Aptana写了一个例子,但Aptana的
智能提示,告诉我我没有insertAfter方法
所以你定义一个罗:
都是定义
insertAfter(神经
功能,targetel)
{
无功parentel = targetel.parentnode;
如果(parentel.lastchild = targetel)
{
parentel.appendchild(楼梯);
}其他
{
parentel.insertbefore(楼梯,targetel。兄弟);
}
}
都是使用的例子
无功txtname = document.getelementbyid(txtname );
无功htmlspan = document.createelement(跨越);
htmlspan.innerhtml =这是一个测试;
InsertAfter(htmlspan,txtname);
插入htmlspan作为brothernode的txtname到txtname节点
总结:
1、appendChild,和在进行节点的方法,都只是一个
函数自定义
2、在,相对于appendChild,更加灵活的插入新节点到目标节点的节点中的任何
位置的数组。
三.在对appendChild和插入新节点的使用,它必须有一个共同的父节点的兄弟