问答详情
源自:9-17 创建文本节点createTextNode

为什么文字输出是undefined

<!doctype html>

<html>

 <head>

  <meta charset="UTF-8">

  <meta name="Generator" content="EditPlus®">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">

  <title>Document</title>

<style type="text/css">


.message{    

width:200px;

height:100px;

background-color:#CCC;}


</style>

</head>

<body>

<script type="text/javascript">

var newp=document.createElement("p");

newp.className="message";

var newText=document.createTextNode("I love JavaScript!").value;

newp.innerHTML=newText;

document.body.appendChild(newp);

</script> 


</body>

</html>


提问者:慕设计8083804 2019-07-27 15:59

个回答

  • Pikachu2016
    2019-08-24 12:24:04

    value代表的是该标签的属性,不等同于它的文本内容