首页 > 试题广场 >

下面代码中"document.write(x.firstCh

[单选题]
下面代码中"document.write(x.firstChild.nodeValue);"的输出结果为(      )
<body>
    <p id="intro">Hello World!</p>
    <script>
        x=document.getElementById("intro");
        document.write(x.firstChild.nodeValue);
    </script>
</body>
  • Hello World!
  • undefined
  • null
  • 其他几项都不对
  1. document.getElementById("intro") 获取了 id 为 "intro" 的 <p> 元素。

  2. x.firstChild 获取这个 <p> 元素的第一个子节点,即文本节点 "Hello World!"。

  3. nodeValue 属性返回文本节点的内容,所以是 "Hello World!"。

  4. document.write() 将内容写入文档,因此页面上会显示 "Hello World!"。

发表于 2025-09-08 14:20:37 回复(0)