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