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>

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM