JavaScript HTML DOM - 改变CSS

改变 HTML 样式

//语法
document.getElementById(id).style.property=new style
<p id="p2">Hello World!</p>

<script>
document.getElementById("p2").style.color="blue";
</script>
 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>W3Cschool教程(w3cschool.cn)</title>
 6 </head>
 7 <body>
 8 
 9 <h1 id="id1">我的标题 1</h1>
10 <button type="button" onclick="document.getElementById('id1').style.color='red'">点我!</button>
12 
13 </body>
14 </html>

 

posted @ 2017-07-07 15:37  gq_orange  阅读(150)  评论(0编辑  收藏  举报