问答详情
源自:3-2 通过ID获取元素

为什么输出这个结果:[object HTMLParagraphElement]

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>document.getElementById</title>

</head>

<body>

<p id="con">JavaScript</p>

<script type="text/javascript">

  var mychar=document.getElementById("con");

  document.write("结果:"+mychar); //输出获取的P标签。 

</script>

</body>

</html>


提问者:慕神8507588 2020-09-02 06:41

个回答

  • 斯逝☆悄清!
    2020-11-18 15:41:57

    确实到这不明白为什么输出的是ull或

    [object HTMLParagraphElement]


  • 慕瓜8116315
    2020-09-02 10:07:38

    document.write("结果:"+mychar.innerHTML);