document.documentElement的一些使用技巧
更新时间:2013年04月18日 14:59:53 作者:
documentElement 属性可返回文档的根节点,接下来为大家详细介绍下document.documentElement的一些使用技巧,感兴趣的朋友可以参考下哈
复制代码 代码如下:
--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="显示节点" onclick="shownode();"/></div>
</body>
</html>
相关文章
html+javascript+bootstrap实现层级多选框全层全选和多选功能
想做一个先按层级排序并可以多选的功能,首先倾向于用多层标签式的,直接选定加在文本域里,接下来通过本文给大家介绍html+javascript+bootstrap实现层级多选框全层全选和多选功能,需要的朋友参考下2017-03-03
最新评论