Javascript elementNodeReference.children不';无法检测文本节点?
Per返回子节点的列表。在我的测试中,这似乎忽略了文本节点。这是正确的吗 让我感到困惑的是,firstChild可以工作,但childrenlist是零 在Firefox 20.0.1中测试 以下是我的测试代码:Javascript elementNodeReference.children不';无法检测文本节点?,javascript,html,dom,Javascript,Html,Dom,Per返回子节点的列表。在我的测试中,这似乎忽略了文本节点。这是正确的吗 让我感到困惑的是,firstChild可以工作,但childrenlist是零 在Firefox 20.0.1中测试 以下是我的测试代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<title></title>
<script>
function checktable() {
var mytable = document.getElementById("mytable");
var cells = mytable.rows[0].cells;
for (var i = 0; i < cells.length; i++) {
console.log("firstChild.nodeValue:", cells[i].firstChild.nodeValue);
console.log("firstChild.data:",cells[i].firstChild.data);
console.log("children.length:",cells[i].children.length);
}
}
function checkdiv() {
var mydiv = document.getElementById("mydiv");
console.log("firstChild.nodeValue:", mydiv.firstChild.nodeValue);
console.log("firstChild.data:",mydiv.firstChild.data);
console.log("children.length:",mydiv.children.length);
}
</script>
<style>
</style>
</head>
<body>
<table id="mytable">
<tr>
<td>Blob</td>
<td>Blab</td>
<td><a href="http://stackoverflow.com">Link</a></td>
</tr>
</table>
<div id="mydiv">
Blib
</div>
<button onclick="checktable()">Check table</button>
<button onclick="checkdiv()">Check div</button>
</body>
</html>
函数检查表(){
var mytable=document.getElementById(“mytable”);
var cells=mytable.rows[0]。单元格;
对于(变量i=0;i
你想要的,不是
前者是节点
的方法,列出子节点。后者是元素
的一种方法,因此列出子元素,在某些情况下更可取。您想要,而不是
前者是节点
的方法,列出子节点。后者是元素
的方法,因此列出子元素,在某些情况下更可取