标题应该会让我的问题变得更好,described.Here就像我的代码一样。
<div id="adiv"><text>Some text</text></div>
<script type="text/javascript">
function vb(){
alert(document.getElementById("adiv").firstChild.nodeValue); //returns null
}
</script>
<input type="button" onclick="vb();" value="get"/>问题出在哪里?
发布于 2010-10-20 20:29:06
为了获得元素节点的合并文本内容:
function vb(){
var textnode = document.getElementById("adiv").firstChild;
alert(textnode.textContent || textnode.innerText);
}为了获取文本节点的文本内容:
function vb(){
alert(document.getElementById("adiv").firstChild.firstChild.nodeValue);
}发布于 2010-10-20 20:22:56
您缺少一个firstChild:
alert(document.getElementById("adiv").firstChild.firstChild.nodeValue);(我知道这听起来很奇怪,但这就是文本节点的工作方式)
发布于 2010-10-20 21:10:09
IE 7不支持<text>节点。
https://stackoverflow.com/questions/3977636
复制相似问题