appendChild定义
Appends a node to the childNodes array for the node.
Supported: IE 5.0+, Mozilla 1.0+, Netscape 6.0+, Safari 1.0+, Opera 7.0+
target.appendChild(newChild)
newChild作为target的子节点插入最后的一子节点之后
var
newElement
=
document.Document.createElement(
‘
label
‘
);
newElement.Element.setAttribute(
‘
value
‘
,
‘
Username:
‘
);
var
usernameText
=
document.Document.getElementById(
‘
username
‘
);
usernameText.appendChild(newElement);
new
child node before an existing child node.
target.insertBefore(newChild,existingChild)
newChild作为target的子节点插入到existingChild节点之前
existingChild为可选项参数,当为null时其效果与appendChild一样
oTest
=
document.getElementById(
“
test
“
);
var
newNode
=
document.createElement(
“
p
“
);
newNode.innerHTML
=
“
This is a test
“
;
oTest.insertBefore(newNode,oTest.childNodes[
0
]);
insertAfter(newEl, targetEl)
{
var
parentEl
=
targetEl.parentNode;
if
(parentEl.lastChild
==
targetEl)
{
parentEl.appendChild(newEl);
}
else
{
parentEl.insertBefore(newEl,targetEl.nextSibling);
}
}
var txtName = document.getElementById(“txtName”);
var htmlSpan = document.createElement(“span”);
htmlSpan.innerHTML = “This is a test”;
insertAfter(htmlSpan,txtName);
将htmlSpan 作为txtName 的兄弟节点插入到txtName 节点之后
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/38511.html