为什么我的html在IE显示正常,在谷歌显示多了一行乱码?而且谷歌浏览器直接卡住了
</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>
<ul id="purchases">
<li>A tin of beans</li>
<li>Cheese</li>
<li>Milk</li>
</ul>
<script>
var paras = document.getElementsByTagName("p");
//alert(paras[0].firstChild.childNodes.length);
alert(paras[0].childNodes[1].nodeValue);//无法获取未定义或 null 引用的属性"nodeName"
</script>
</body>
下面是截图
经试验,按楼主所贴代码,在IE和chrome里面弹出的都是null,没有出现乱码这里,至于为什么弹出是null,因为childNodes[1]是
<em>qwqw</em>
,是element,他的nodeValue就是null,