Welcome to DOM World!
if (node.nodeType != null) {
temp += "nodeType:" + node.nodeType + "\n";
}
else {
temp += "nodeType:null!\n";
}
if (node.nodeValue != null) {
temp += "nodeValue:" + node.nodeValue + "\n";
}
else {
temp += "nodeValue:null!\n";
}
return temp;
}
var currentElement = document.getElementById('p1');
var msg = nodeStatus(currentElement);
//alert(msg);
var firstChild = currentElement.firstChild;
msg += nodeStatus(firstChild);
//父亲的下一个儿子->弟弟
var youngerBrother = firstChild.nextSibling;
msg += nodeStatus(youngerBrother);
//2弟的儿子=p父亲的大孙子
var grandSon = youngerBrother.firstChild;
msg += nodeStatus(grandSon);
//孙子的父亲
var grandSonParent = grandSon.parentNode;
msg += nodeStatus(grandSonParent);
//孙子的父亲的兄长
var grandSonParentElderBrother = grandSonParent.previousSibling
msg += nodeStatus(grandSonParentElderBrother);
//大哥的父亲
var parent = grandSonParentElderBrother.parentNode;
msg += nodeStatus(parent);
//父亲的小儿子
var lastChild = parent.lastChild;
msg += nodeStatus(lastChild);
//父亲的所有儿子
var allChildInfo = "";
var allChild = parent.childNodes;
for (var i = 0; i allChildInfo += nodeStatus(allChild[i]);
}
//alert(msg);
以上就是文档对象模型的实例代码的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号