css随机改变页面的背景色

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body id="body">
<input type='button'  value='刷新页面,随机改变颜色'/>
</body>
</html>
<script>
    var r = Math.floor(Math.random() *256);
    var g = Math.floor(Math.random() *256);
    var b = Math.floor(Math.random() *256);
    console.log(b);
    var color = "rgb("+r+","+g+","+b+")";
    console.log(color)
    var bd = document.getElementById("body")
    bd.style.background= color;
</script>

点击刷新按钮,切换颜色

css随机改变页面的背景色

 

上一篇:MatrixDB导入csv时序数据


下一篇:1008Elevator