老师 那我这样改不是更简便吗 没看懂有什么意义 谢谢老师
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#myBox {
font-weight: bold;
font-size: 1.2em;
background: red;
}
</style>
</head>
<body>
<div id="myBox">imooc</div>
<script>
var myBox = document.getElementById("myBox");
// myBox.style.fontWeight = "bold";
// myBox.style.fontSize = "1.2em";
// myBox.style.background = "red";
// myBox.className = "oneBox"
</script>
</body>
</html>
正在回答
同学你好,这样写也是可以的,该章节的内容讲的是通过style属性,去控制元素的样式;
两者的区别是同学的写法是使用css样式在style标签中进行的,而课程中的这种方法是通过js在script标签中使用的;
祝学习愉快~

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星