代码如下:
--documentElement 属性可返回文档的根节点。
function shownode() {
var ohtml = document.documentElement;
//alert(ohtml.nodeName);
//alert(ohtml.childNodes.length);
//alert(ohtml.childNodes[1].nodeName); //获取body
//var obody = ohtml.childNodes[1]; //一层层的找到div
var obody = ohtml.lastChild; //快速获取ohtml的最后一个子节点
//alert(obody.childNodes[0].nodeName);
//alert(obody.parentNode.nodeName); //根据子节点找到想要的父节点
//alert(obody.previousSibling.nodeName);
var ohead = ohtml.childNodes[0];
// alert(ohead.nextSibling.nodeName);
}
script>
//body如果和div之间有空格,或者每个层之间有空格,会影响获取结果
第一层 第二层
第三层
第四层