菜单切换
FACESOHO知行者
心灵
记录
远方
赞赏工具
源代码:
点击运行
保存
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>小鸟启蒙(facesoho.com)</title> </head> <body> <p>点击按钮计算 DIV 的背景颜色。</p> <p><button onclick="myFunction()">点我</button></p> <div id="test" style="height:50px;background-color:rgb(178, 116, 230);">测试 DIV</div> <p>计算值为:<span id="demo"></span></p> <script> function myFunction(){ var elem = document.getElementById("test"); var theCSSprop = window.getComputedStyle(elem, null).getPropertyValue("background-color"); document.getElementById("demo").innerHTML = theCSSprop; } </script> </body> </html>
运行结果