javascript相邻节点元素获取

2022-10-15,,,,

<script>
window.onload = function () {
var myLinkItem = document.getElementById('linkItem');
var first = firstSibling(myLinkItem.parentNode);
var last = lastSibling(myLinkItem.parentNode);
alert(getTextContent(first));
alert(getTextContent(last));
}
function lastSibling(node) {
var tempObj = node.parentNode.lastChild;
while (tempObj.nodeType != 1 && tempObj.previousSibling != null) {
tempObj = tempObj.previousSibling;
}
return (tempObj.nodeType == 1) ? tempObj : false;
}
function firstSibling(node) {
var tempObj = node.parentNode.firstChild;
while (tempObj.nodeType != 1 && tempObj.nextSibling != null) {
tempObj = tempObj.nextSibling;
}
return (tempObj.nodeType == 1) ? tempObj : false;
}
function getTextContent(node) {
return node.firstChild.nodeType;
}
</script>

javascript相邻节点元素获取的相关教程结束。

《javascript相邻节点元素获取.doc》

下载本文的Word格式文档,以方便收藏与打印。