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

看下对吗?

<!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.innerText); //输出获取的P标签。 

</script>

</body>

</html>


提问者:qq_童言无忌殇了我i_0 2020-08-11 16:59

个回答

  • 爬山不停
    2020-08-19 15:29:38

    没毛病。innerText也可以换成innerHTML