js获取html标签
document.documentElement
js获取body标签
document.body
以react为例,当页面属性(status)改变时,动态改变html和body的背景色,代码如下
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15useEffect(() => { switch (status) { case 'a': document.body.style.background = 'color1' // 修改body的背景色为color1 document.documentElement.style.background = 'color1' // 修改html的背景色为color1 break case 'b': document.body.style.background = 'color2' document.documentElement.style.background = 'color2' break default: break } }, [status])
最后
以上就是爱笑篮球最近收集整理的关于js动态修改html、body的css属性的全部内容,更多相关js动态修改html、body内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复