使用 onmouseover 属性更改网页背景颜色
htmlweb developmentfront end technology更新于 2026/1/30 6:36:17
onmouseover 属性允许您在鼠标指针移动到元素上时设置脚本。要更改背景颜色,请使用 HTML DOM backgroundColor 属性。
让我们看一个实现 onmouseover 属性并更改背景颜色的示例 −
示例
<!DOCTYPE html> <html> <body> <h2>Heading Two</h2> <a onmouseover="document.body.style.backgroundColor ='orange'">Hover over me to change the background color.</a><br> </body> </html>
输出

现在将鼠标悬停在文本上即可更改网页的背景颜色 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

