SpecialMe
2020-06-30 21:44
<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>
这一行打错了是createElement,
你打成了 carateElement
我的是正常显示,对比一下就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>
createElement
JavaScript进阶篇
468276 学习 · 21892 问题
相似问题