为什么我的js部分显示不出来啊?我哪里写错了吗?详解必采纳
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Documenttitle>
head>
<body>
<ul id="nodeList">
<li>nodeNameli>
<li>nodeValueli>
<li>nodeTypeli>
ul>
<p>p>
<script>
var nodes=document.getElementById("nodeList");
var type1=nodes.firstChild.nodeType;
var type2=nodes.firstChild.firstChild.nodeType;
var name=nodes.firstChild.firstChild.nodeName;
var str=nodes.firstChild.firstChild.nodeValue;
var reason="type1:"+type1+"
type2:"+type2+"
name:"+name+"
str:"+str;
document.getElementById("nodeList").nextSibling.innerHTML=reason;
script>
body>
html>
我看到这段代码中有以下几个错误:
没有定义变量nodeList。在第18行的document.getElementById("nodeList")中,它引用了一个名为nodeList的元素,但在HTML代码中并没有定义该元素。
在第18行,它调用了getElementById方法来获取元素,但是实际上这个方法应该调用getElementsById。它同样没有定义nodeList。
在第22行,它试图访问一个名为nextSibling的属性,但是这个属性不存在。应该改为调用nextElementSibling属性。
在第22行,它试图访问innerHTML属性来更新段落元素的内容,但是它应该使用textContent属性来更新文本内容。