<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <p id="imooc1"></p> <p id="imooc2"></p> <script type="text/javascript"> var mychar=document.getElementById("imooc1"); mychar.innerHTML = "您好!"; document.write(mychar.innerHTML); mychar.style.color = "red"; } </script> </body> </html>
删除那个括号就行了
<script type="text/javascript">
var mychar=document.getElementById("imooc1");
mychar.innerHTML = "您好!";
document.write(mychar.innerHTML);
mychar.style.color = "red";
} //这里多了个大括号了,我运行过你的代码,删了这个就可以了
</script>
在代码的16行多了一个{