<style type="text/css">
.chen{
width:200px;
height:100px;
background-color:#CCC;}
</style>
<script>
var pNode = document.createElement("p");
pNode.className = "chen";
var textNode = document.createTextNode("我不想太悚");
pNode.appendChild(textNode);
//问题来了,为什么这样给 文本节点加css属性 不行
textNode.style.color="red"
document.body.appendChild(pNode)
</script>
2 回答
qq_青枣工作室_0
TA贡献446条经验 获得超754个赞
文本节点没有css属性的,只能在标签上加css属性。
<style type="text/css">
.chen{
width:200px;
height:100px;
background-color:#CCC;}
</style>
<body>
<script>
var pNode = document.createElement("p");
pNode.className = "chen";
var textNode = document.createTextNode("我不想太悚");
pNode.appendChild(textNode);
//文本节点没有css属性,只能在标签上加
pNode.style.color="red"
document.body.appendChild(pNode)
</script>
</body>添加回答
举报
0/150
提交
取消
