手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >document.documentElement的一些使用技巧
document.documentElement的一些使用技巧
摘要:复制代码代码如下:--documentElement属性可返回文档的根节点。functionshownode(){varohtml=docu...

复制代码 代码如下:

--documentElement 属性可返回文档的根节点。

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title></title>

<script type="text/javascript">

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>

</head>

//body如果和div之间有空格,或者每个层之间有空格,会影响获取结果

<body><div id="div1">第一层</div> <div id="div2">第二层</div>

<div>第三层<img src="images/4.jpg" /></div>

<div>

第四层<input id="Button1" type="button" value="显示节点"/></div>

</body>

</html>

【document.documentElement的一些使用技巧】相关文章:

js禁止页面刷新与后退的方法

TypeError document.getElementById(...) is null错误原因

EasyUI闪屏EasyUI页面加载提示(原理+代码+效果图)

AngularJS中$interval的用法详解

document对象execCommand的command参数介绍

document 和 document.all 分别什么时候用

document.getElementById的一些细节

JS、HTML代码运行工具

tagName的使用,留一笔

AngularJs中route的使用方法和配置

精品推荐
分类导航