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

为什么不显示????

<html>

<head>

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

<title>无标题文档</title>

<style type="text/css">


.message{    

width:200px;

height:100px;

background-color:#CCC;}

</style>

</head>

<body>

<script type="text/javascript">

    var element=document.carateElement("p");

    element.className="message";

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

    element.appendChild(textNode);

    document.body.appendChild(element);

</script> 


</body>

</html>


提问者:SpecialMe 2020-06-30 21:44

个回答

  • weixin_慕用8515188
    2022-07-06 17:03:53

    http://img4.mukewang.com/62c54f90000110bb04730355.jpg

    这一行打错了是createElement,

    你打成了          carateElement

  • 慕尼黑1441384
    2020-08-05 14:51:25

    我的是正常显示,对比一下就ok了;

    <!DOCTYPE HTML>

    <html>

    <head>

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

    <title>无标题文档</title>

    <style type="text/css">


    .message{    

    width:200px;

    height:100px;

    background-color:#CCC;}

    </style>

    </head>

    <body>

    <script type="text/javascript">

    var p=document.createElement('p');

    var text=document.createTextNode('I love javaScript.');

    p.className='message';

    p.appendChild(text);

    document.body.appendChild(p);

    </script> 


    </body>

    </html>


  • 狮子奋迅
    2020-07-08 17:55:28

    createElement