JavaScript实现按钮改变网页背景色

运行效果:

 

 

 

 

 

 

 

源代码:

 1 <!DOCTYPE html>
 2 <html lang="zh">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>改变背景颜色</title>
 6 </head>
 7 <body>
 8 <div style="margin-top: 100px;margin-left: 100px;">
 9     <button type="button" onclick="ChangeBackgroundColor('red')"></button>
10     <button type="button" onclick="ChangeBackgroundColor('blue')"></button>
11     <button type="button" onclick="ChangeBackgroundColor('green')">绿</button>
12 </div>
13 
14 <script type="text/javascript">
15     function ChangeBackgroundColor(new_bgcolor) {
16         document.bgColor = new_bgcolor;
17     }
18 </script>
19 </body>
20 </html>

 

 

posted @ 2019-11-22 07:57  孤云jh  阅读(3233)  评论(0编辑  收藏  举报