1、新建文件创建div
2、效果如图
3、js获取元素
4、js改变样式的一种方式
5、js改变样式的另一种方式
6、附上源码<body><div id="box">hello word</div><button onclick="dem()" id="btn1">点击</button><script>var oBox = document.getElementById("box"); var oBtn1 = document.getElementById("btn1"); function dem(){ oBox.style.color= "red"; } /* oBtn1.onclick = function(){ oBox.style.color= "red"; }*/</script></body>