このサンプルは、マウスを「赤」、「緑」、「青」のボックス上に移動すると、Webページの背景色をその色で切り替えます。
Webページの背景色を切り替えるには、BODY要素のstyle.backgroundプロパティに背景色のカラー(red,green,blue)を設定します。「this.style.backgroundColor」のthisは、onmouseoverイベントが発生したTD要素を指します。
function changeColor() {
document.body.style.background =
this.style.backgroundColor;
}
このサンプルは、マウスを「赤」、「緑」、「青」のボックス上に移動すると、Webページの背景色をその色で切り替えます。
Webページの背景色を切り替えるには、BODY要素のstyle.backgroundプロパティに背景色のカラー(red,green,blue)を設定します。「this.style.backgroundColor」のthisは、onmouseoverイベントが発生したTD要素を指します。
function changeColor() {
document.body.style.background =
this.style.backgroundColor;
}