</head>
<body>
<h1>What to buy</h1>
<p title="a gentle reminder">Don't <em>qwqw</em>forget to buy this stuff.</p>
<p>This is just a test</p>
<script>
var paras = document.getElementsByTagName("p");
alert(paras[0].childNodes[1].nodeValue);//为什么显示NULL??应该显示qwqw啊??
</script>
</body>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
只有文本节点的
nodeValue才会返回真正的文本paras[0].childNodes[1].childNodes[0].nodeValueparas[0].childNodes[1]取得<em>qwqw</em>内部文字为文本节点,因此还需取一层
paras[0].childNodes[1].childNodes[0].nodeValue