改变 HTML 元素的背景色
- <!DOCTYPE html>
- <html>
- <head>
-
- <script>
- function bgChange(bg) {
- document.body.style.background = bg;
- }
- </script>
- </head>
- <body>
-
- <h1>改变背景颜色</h1>
-
- <p>请把鼠标移动到方块上。</p>
-
- <table style="width:300px;height:100px">
- <tr>
- <td onmouseover="bgChange(this.style.backgroundColor)"
- onmouseout="bgChange('transparent')"
- style="background-color:Khaki">
- </td>
- <td onmouseover="bgChange(this.style.backgroundColor)"
- onmouseout="bgChange('transparent')"
- style="background-color:PaleGreen">
- </td>
- <td onmouseover="bgChange(this.style.backgroundColor)"
- onmouseout="bgChange('transparent')"
- style="background-color:Silver">
- </td>
- </tr>
- </table>
-
- </body>
- </html>