创建文本节点createTextNode

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>创建文本节点createTextNode</title>
<style type="text/css">

.message{    
    width:200px;
    height:100px;
    background-color:#CCC;}
    
</style>
</head>
<body>
<script type="text/javascript">
 var element = document.createElement("p");
 element.className = "message";
 var textNode = document.createTextNode("I love JavaScript!");
 element.appendChild(textNode);
 document.body.appendChild(element);
</script> 

</body>
</html>

 

posted @ 2017-11-13 12:42  赵翔个人博客  阅读(940)  评论(0编辑  收藏  举报