document.defaultView:
一般情况下,在google浏览器开发者工具的console面板下运行document.defaultView === window
,这个是会返回true的。首先,我们得知道defaultView这个属性到底是什么意思呢?查下MDN:在浏览器中,返回与当前document所关联的window对象,如果没有则返回null
,而且是一个只读属性。前面说的一般情况下,是没问题是因为在Firefox浏览器低版本中会出问题,必须使用document.defaultView.getComputedStyle
来获取其style
属性。
children与childNodes的区别
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="parentDiv">
<!--注释-->
<div></div>
</div>
<script type="text/javascript">
console.log(document.getElementById('parentDiv').childNodes); //NodeList[5]
console.log(document.getElementById('parentDiv').children) ; //HTMLCollection[1]
</script>
</body>
</html>
childNodes返回的是NodeList数组,是子节点的属性,而children是返回子元素,返回的是元素的属性。
Element是继承与Node类型的,Node的NodeType具有多选值,而Element只是其中的一种。