<!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 element=document.createElement("p");
element.setAttribute(class,message); //一直显示这里有错
var text=document.createTextNode("<strong>i love javascript</strong>");
element.appendChild(text);
//element.class="message";
//element.innerHTML="I love javascript";
document.body.appendChild(element);
</script>
</body>
</html>
setAttribute("class","message") 要带上引号,否则会认为是变量