createElement,createTextNode,appendChild

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <script>
        window.onload=function () {
             var div1=document.getElementById('div1');
             var para=document.createElement('p');
             var txt=document.createTextNode('hello word');
                 div1.appendChild(para);
                 para.appendChild(txt);

        }
    </script>
</head>
<body>
<div id="div1">
    
</div>    
</body>
</html>

 

posted @ 2016-06-22 13:41  Cutelady  阅读(135)  评论(0编辑  收藏  举报